Swift Language Reviews II

Source: Internet
Author: User

First, the data type

1, the basic type of package

Swift provides its own versions of all fundamental C and objective-c types, including for Int integers, Double and Float F or floating-point values

2. New Type

Swift introduces advanced types not found in objective-c, such as tuples.

Tuples enable you to create and pass around groupings of values.

3. Type-Safe language

Swift is a type-safe language, which means the language helps you are clear about the types of values your code can work with.

4. Data type Conversion

    1. let three = 3
    2. let pointOneFourOneFiveNine = 0.14159
    3. let pi = Double(three) + pointOneFourOneFiveNine
    4. // pi equals 3.14159, and is inferred to be of type Double

5, tuples

    1. let http404Error = (404, "Not Found")
    1. let (statusCode, statusMessage) = http404Error
    2. print("The status code is \(statusCode)")
    3. // Prints "The status code is 404"
    4. print("The status message is \(statusMessage)")
    5. // Prints "The status message is Not Found"

6. Optionals

    1. let possibleNumber = "123"
    2. let convertedNumber = Int(possibleNumber)

Type inference Convertednumber:int?

7. Optional Binding

You use the optional binding to the find out whether an optional contains a value

8, implicitly unwrapped optionals

. You write an implicitly unwrapped optional by placing an exclamation mark ( String! ) rather than a question mark ( String? ) afte R the type that is want to make optional.

Swift Language Reviews II

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.