Swift Tour 에세이 요약(2)

1642 단어 swift
Type Aliases
typealias AudioSample = UInt16

Booleans
boolean 이외의 값은 bool로 대체되지 않습니다. 예를 들어,
let i = 1

if i {

  // this example will not compile, and will report an error

}

Tuples
예를 들어 HTTPStatus Code("404", "Not Found")
let http404Error = (404, "Not Found")

// http404Error is of type (Int, String)

Access Tuple:

let (statusCode, statusMessage) = heep404Error

println("This status code is \(statusCode)")

// prints "The status code is 404"

println("The statuis message is \(statusMessage)")

// prints "The status message is Not Found"

, _ , :

let (justTheStatusCode, _) = http404Error

println("The status code is \(justTheStatusCode)")

// prints "The status code is 404"

access tuple :

println("The status code is \(http404Error.0)")

// prints "The status code is 404"

println("The status message is \(http404Error.1)")

// prints "The status message is Not Found"

Tuple define

let http200Status = (statusCode: 200, description: "OK")

access

println("The status code is \(http200status.statusCode)")

println("The status code message is \(http200status.description)")

좋은 웹페이지 즐겨찾기