Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. // Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
  2. // Target: x86_64-apple-darwin18.6.0
  3.  
  4. // Chapter: The Basics
  5.  
  6. // Constant declaration without immediate value assignment is legal.
  7. let a: Int
  8. a = 0
  9.  
  10. // Distinct integer types are comparable.
  11. let b: UInt = 0
  12. let c = a == b
  13.  
  14. // Typealiased values can be stored within an typealiased type's container.
  15. typealias Boolean = Bool
  16.  
  17. let d: Boolean = false
  18. let e = [c, d] // type: [Bool]
  19. let f = [d, c] // type: [Boolean]
  20.  
  21. // Chapter: Basic Operators
  22.  
  23. // Nil-coalescing operator in-depth.
  24. let g: String? = nil
  25. let h: String? = nil
  26. let i = g ?? h // type: String?
  27. let j = g ?? "" // type: String
  28.  
  29. // Unary logical operators work in constant declaration and assignment.
  30. let k = !true
  31.  
  32. // Chapter: Collection Types
  33.  
  34. // Use tuple's member(s) as variable(s) in iteration of a Dictionary.
  35. let l = [true: 1, false: 0]
  36. for (_, var lv) in l {
  37. lv += 1
  38. }
  39.  
  40. // Chapter: Control Flow
  41.  
  42. let m = stride(from: 0, to: 1, by: 1) // type: StrideTo<Int>
  43. let n = stride(from: 0, through: 1, by: 1) // type: StrideThrough<Int>
  44.  
  45. // Chapter: Functions
  46.  
  47. // "Although it's possible for multiple parameters to have the same argument label, ..."
  48. func o(p q: Bool, p r: Bool) -> Bool {
  49. return !q || r
  50. }
  51. let s = o(p: true, p: false)
  52.  
  53. // Optional function types.
  54. let t: ((Bool, Bool) -> Bool)? = o
  55. let u = t!(false, false)
  56.  
  57. // Chapter: Enumeration
  58.  
  59. // Boolean raw values are not allowed because it does not conform to RawRepresentable
  60. // enum A: Bool {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement