swift2之元组

[code]
//
// main.swift
// t1
//
// Created by liu qing on 15/9/13.
// Copyright (c) 2015年 aha68. All rights reserved.
//

import Foundation

//println("Hello, World!") //output function
//tuple 元组 类似as3里的object
let (x,y) = (1,2)
println("x is \(x) and y is \(y)")

let http404Error = (404,"not found") //定义一个由int和string组成的元组
println(http404Error)

let (code,info) = http404Error
println(code)

let (code2,_) = http404Error // 下划线过滤不需要访问的值
println(code2)

println("code is \(http404Error.0)") //序号访问元素

let h200 = (s:1,t:"ok")
println(h200.1)
[/code]

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>