Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
- // Target: x86_64-apple-darwin18.6.0
- // Chapter: The Basics
- // Constant declaration without immediate value assignment is legal.
- let a: Int
- a = 0
- // Distinct integer types are comparable.
- let b: UInt = 0
- let c = a == b
- // Typealiased values can be stored within an typealiased type's container.
- typealias Boolean = Bool
- let d: Boolean = false
- let e = [c, d] // type: [Bool]
- let f = [d, c] // type: [Boolean]
- // Chapter: Basic Operators
- // Nil-coalescing operator in-depth.
- let g: String? = nil
- let h: String? = nil
- let i = g ?? h // type: String?
- let j = g ?? "" // type: String
- // Unary logical operators work in constant declaration and assignment.
- let k = !true
- // Chapter: Collection Types
- // Use tuple's member(s) as variable(s) in iteration of a Dictionary.
- let l = [true: 1, false: 0]
- for (_, var lv) in l {
- lv += 1
- }
- // Chapter: Control Flow
- let m = stride(from: 0, to: 1, by: 1) // type: StrideTo<Int>
- let n = stride(from: 0, through: 1, by: 1) // type: StrideThrough<Int>
- // Chapter: Functions
- // "Although it's possible for multiple parameters to have the same argument label, ..."
- func o(p q: Bool, p r: Bool) -> Bool {
- return !q || r
- }
- let s = o(p: true, p: false)
- // Optional function types.
- let t: ((Bool, Bool) -> Bool)? = o
- let u = t!(false, false)
- // Chapter: Enumeration
- // Boolean raw values are not allowed because it does not conform to RawRepresentable
- // enum A: Bool {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement