Swift首页投稿(暂停使用,暂停投稿)iOS 开发

Swift基础语法-元组--OC中没有的概念

2016-07-30  本文已影响124人  DwightChan

什么是元组

定义元组

let student = ("cdh", 22, 1.88)
print(student)
print(student.0)
print(student.1)
print(student.2)
let student1: (String, Int, Double) = ("cdh", 22, 1.88)

定义元组其它方式

let student2 = (name:"cdh",age:22,score:1.88)
print(student2.name)
print(student2.age)
print(student2.score)
let (name , age , score) =  ("cdh", 22, 1.88)
print(name)
print(age)
print(score)
let student2 : (name , age , score) = ("cdh", 24, 99.9) // 这种定义方式是错误的
let student4 = ("cdh",10,20)
let (name , age , _) = student
print(name)
print(age)

上一篇下一篇

猜你喜欢

热点阅读