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
let three = 3
let pointOneFourOneFiveNine = 0.14159
let pi = Double(three) + pointOneFourOneFiveNine
// pi equals 3.14159, and is inferred to be of type Double
5, tuples
let http404Error = (404, "Not Found")
let (statusCode, statusMessage) = http404Error
print("The status code is \(statusCode)")
// Prints "The status code is 404"
print("The status message is \(statusMessage)")
// Prints "The status message is Not Found"
6. Optionals
let possibleNumber = "123"
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