//: Playground - noun: a place where people can play import UIKit let page = (1,"第一页内容") page.0 page.1 let (pageIndex,pageContent) = page pageIndex pageContent //定义 tuple 的下标 类似 dict let antherPage:(pageIndex:Int, pageText:String) = (10 ,"cccccc text") //用 下标来访问 antherPage.pageIndex antherPage.pageText //Tuple 作为函数返回值 func currentPage() -> (pageInedex:Int , pageText:String) { return (1,"内容内容") } currentPage().pageText let books = [("python 入门",15,509,"计算机"), ("算法导论",4,300,"理论"), ("互联网思维",6,400 ,"商业")] // switch tupe _ 表示 忽略 for book in books { println("\(book.0) -") switch book { //定义变量 case (_,15,let chapterCount,let genre): println("这本书是给 python初学者用") //区间条件 case (_,5...7,_,_): println("创业书籍") default: println("其他书籍") } } // 利用 Tuple 交换 2个变量值 var name1 = "kai" var name2 = "super man" (name1,name2)=(name2,name1) name1

hqman
198 声望8 粉丝

« 上一篇
swift #6 类
下一篇 »
IOS location