标签:
swift版的元组
说明
元组的内容并不多,使用的话跟普通变量类似,以下是测试源码:
// // ViewController.swift // Tuples // // Created by YouXianMing on 15/10/12. // import UIKit class ViewController: UIViewController { var tuplesValues : (duration : NSTimeInterval, animated : Bool)? override func viewDidLoad() { super.viewDidLoad() unnamedTuples() namedTuples() tuplesValues = (duration : 10, animated : true) if let _ = tuplesValues { print(tuplesValues!.duration) print(tuplesValues!.animated) } else { } } // Unnamed Tuples func unnamedTuples() { let tipAndTotalOne = (4.00, 25.19) let tipAndTotalTwo : (Double, Double) = (4.00, 25.19) print(tipAndTotalOne) print(tipAndTotalTwo) } // Named Tuples func namedTuples() { let tipAndTotalNamedOne = (tipAmt : 4.00, total : 25.19) print("\(tipAndTotalNamedOne.tipAmt) + \(tipAndTotalNamedOne.total)") let tipAndTotalNamedTwo : (tipAmt : Double, total : Double) = (4.00, 25.19) print("\(tipAndTotalNamedTwo.tipAmt) + \(tipAndTotalNamedTwo.total)") } // Returning Tuples func calcTipWithTipPct(tipPct:Double) -> (tipAmt : Double, total : Double) { let tipAmt = tipPct * 6 let finalTotal = tipAmt * 0.56 return (tipAmt, finalTotal) } // animationOptionsWith func animationOptionsWith(duration : NSTimeInterval, animated : Bool) { } }
细节
标签:
原文地址:http://www.cnblogs.com/YouXianMing/p/4871622.html