Swift元组的创建--使用
2016-12-22 14:09
447 查看
//元组把多个值组合成一个值
其中的值类型可以不同.
let HttpErrorCode = (404,"not found")
let (status,statusMe) =
HttpErrorCode
//读取方式 0,1,2,3,4,下标.
print(HttpErrorCode.0)
print("The status code ==
\(status)")
print("The status mess ==
\(statusMe)")
let (abc,_) =
HttpErrorCode
print(abc)
//元组的赋值
let http200err = (statuss:200,errcodes:"notfound")
print(http200err.statuss)
print(http200err.errcodes)
//元组在临时组织值得时候很有用,但是并不适合创建复杂的数据结构.若复杂的数据结构
使用类和结构体.
其中的值类型可以不同.
let HttpErrorCode = (404,"not found")
let (status,statusMe) =
HttpErrorCode
//读取方式 0,1,2,3,4,下标.
print(HttpErrorCode.0)
print("The status code ==
\(status)")
print("The status mess ==
\(statusMe)")
let (abc,_) =
HttpErrorCode
print(abc)
//元组的赋值
let http200err = (statuss:200,errcodes:"notfound")
print(http200err.statuss)
print(http200err.errcodes)
//元组在临时组织值得时候很有用,但是并不适合创建复杂的数据结构.若复杂的数据结构
使用类和结构体.
相关文章推荐
- 使用Swift开发iOS项目、UI创建、方法调用
- 使用Swift创建Swift模块 - 静态链接库
- 使用 Realm 和 Swift 创建 ToDo 应用
- 分别使用OC和Swift语法创建单例
- 使用 Swift 创建简单的二维码扫描应用
- 使用 Swift 创建简单的二维码扫描应用
- 使用Swift在Xcode中创建自定义控件
- Swift 中使用 SQLite——创建数据表
- Swift-UITextField的创建和使用详解
- Swift 使用Builder 文件 创建 Rings
- Swift - 使用storyboard创建表格视图(TableViewController)
- 使用Swift创建一个SOAP的请求
- swift中的block的创建和使用
- Swift UIButton 和 UILabel 的详细解释和创建使用
- 使用Swift创建Swift模块 - 静态链接库
- Swift学习 接口的创建与使用
- swift中cell的两种创建区别和extension的使用。让我们开发更有条理
- ios开发中使用工厂模式创建ui控件(swift)
- iOS使用Swift创建UITableView
- Swift 函数的基本写法与使用元组实现返回多个值(四)