Swift中的元组(turple)
2015-12-08 00:16
411 查看
元组是多个值组成的复合值类型
import Foundation
let money = (100,"EUR")
let currency = money.1
let amout = money.0
print("I have \(amout) \(currency) ") //I have 100 EUR
let money2 = (amout: 100,currency: "EUR")
let currency2 = money2.currency
let amout2 = money2.amout
print("I have \(amout2) \(currency2) ")// I have 100 EUR
func format(input: (Int,String)) -> String {
return "I have \(input.0) \(input.1) in my wallet"
}
print(format(money)) // This prints "I have 100 USD in my wallet"
import Foundation
let money = (100,"EUR")
let currency = money.1
let amout = money.0
print("I have \(amout) \(currency) ") //I have 100 EUR
let money2 = (amout: 100,currency: "EUR")
let currency2 = money2.currency
let amout2 = money2.amout
print("I have \(amout2) \(currency2) ")// I have 100 EUR
func format(input: (Int,String)) -> String {
return "I have \(input.0) \(input.1) in my wallet"
}
print(format(money)) // This prints "I have 100 USD in my wallet"
相关文章推荐
- Swift 开源那点事
- Swift中的闭包
- Swift -- 泛型
- Swift -- protocol、extension
- Swift学习——Swift解释具体的基础(六)
- 程序猿必知的swift单例编写的正确方式
- ios9中新建swift工程并采用OC混编的方式,keywindow=nil的解决办法
- Swift学习笔记 -- 简单值
- Swift Up and Running——使用Tuple打包类型
- Swift Up and Running——字符、Unicode和字符串
- Swift Up and Running——整数和浮点数
- swift学习之UIButton
- swift学习之Label
- swift实际使用中遇到的问题及解决
- fir.im Weekly - 进击的 Swift
- Ubuntu 15.10部署Swift开发环境
- [Swift]swift单例模式的三种写法
- Swift Up and Running——变量和常量
- Swift中使用do-catch语句进行异常处理
- 《Swift 的界面之间的传值,详细介绍3种传值方式》 正向传值、协议传值、闭包