Swift Tour Essay summary (2)

Source: Internet
Author: User



Type Aliases

typealias AudioSample = UInt16
Booleans

Non-boolean values are not replaced by bool, for example:

let i = 1
if i {
// this example will not compile, and will report an error
}
Tuples

Example: 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"
Shorthand, use _ instead of unnecessary variables, for example:

let (justTheStatusCode, _) = http404Error
println ("The status code is \ (justTheStatusCode)")
// prints "The status code is 404"
Another access tuple method:

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's complete definition

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

println ("The status code is \ (http200status.statusCode)")
println ("The status code message is \ (http200status.description)")
Swift Tour Essay Summary (2)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.