Upgrade to Pro — share decks privately, control downloads, hide ads and more …

UnderstandingYourToddler.pdf

 UnderstandingYourToddler.pdf

Often we can go back and look at someone's toddler years and see signs of the person they would become. In this talk we look at the proposals for Swift 3 and imagine the language Swift will become.

dimsumthinking

May 27, 2016
Tweet

More Decks by dimsumthinking

Other Decks in Programming

Transcript

  1. ?

  2. Understanding Your Toddler iOSConf 2016 Daniel H Steinberg @dimsumthinking No,

    this is not the same talk I gave last week at UIKonf
  3. ARC

  4. API design guidelines Focus and refine the language Adoption of

    naming guidelines in key APIs Automatic application of naming guidelines to imported Objective-C APIs Swiftification of imported Objective-C APIs Improvements to tooling quality
  5. API design guidelines Focus and refine the language Adoption of

    naming guidelines in key APIs Automatic application of naming guidelines to imported Objective-C APIs Swiftification of imported Objective-C APIs Improvements to tooling quality
  6. API design guidelines Focus and refine the language Adoption of

    naming guidelines in key APIs Automatic application of naming guidelines to imported Objective-C APIs Swiftification of imported Objective-C APIs Improvements to tooling quality
  7. API design guidelines Focus and refine the language Adoption of

    naming guidelines in key APIs Automatic application of naming guidelines to imported Objective-C APIs Swiftification of imported Objective-C APIs Improvements to tooling quality
  8. API design guidelines Focus and refine the language Adoption of

    naming guidelines in key APIs Automatic application of naming guidelines to imported Objective-C APIs Swiftification of imported Objective-C APIs Improvements to tooling quality
  9. API design guidelines Focus and refine the language Adoption of

    naming guidelines in key APIs Automatic application of naming guidelines to imported Objective-C APIs Swiftification of imported Objective-C APIs Improvements to tooling quality
  10. class MyClass { private var myProperty = "Hello" private func

    myPrivateMethod() { print(myProperty) } fileprivate func myFilePrivateMethod(numberOfTimes times: Int) { for _ in 1 ... times { myPrivateMethod() } } } extension MyClass { func myExtensionMethod(numberOfTimes times: Int) { myFilePrivateMethod(numberOfTimes: times) } }
  11. class MyClass { private var myProperty = "Hello" private func

    myPrivateMethod() { print(myProperty) } fileprivate func myFilePrivateMethod(numberOfTimes times: Int) { for _ in 1 ... times { myPrivateMethod() } } } extension MyClass { func myExtensionMethod(numberOfTimes times: Int) { myFilePrivateMethod(numberOfTimes: times) } }
  12. class MyClass { private var myProperty = "Hello" private func

    myPrivateMethod() { print(myProperty) } fileprivate func myFilePrivateMethod(numberOfTimes times: Int) { for _ in 1 ... times { myPrivateMethod() } } } extension MyClass { func myExtensionMethod(numberOfTimes times: Int) { myFilePrivateMethod(numberOfTimes: times) } }
  13. class MyClass { private var myProperty = "Hello" private func

    myPrivateMethod() { print(myProperty) } fileprivate func myFilePrivateMethod(numberOfTimes times: Int) { for _ in 1 ... times { myPrivateMethod() } } } extension MyClass { func myExtensionMethod(numberOfTimes times: Int) { myFilePrivateMethod(numberOfTimes: times) } }
  14. class MyClass { private var myProperty = "Hello" private func

    myPrivateMethod() { print(myProperty) } fileprivate func myFilePrivateMethod(numberOfTimes times: Int) { for _ in 1 ... times { myPrivateMethod() } } } extension MyClass { func myExtensionMethod(numberOfTimes times: Int) { myFilePrivateMethod(numberOfTimes: times) } }
  15. func double(input: Int) -> Int { var localInput = input

    localInput = localInput * 2 return localInput }
  16. func double(input: Int) -> Int { var localInput = input

    localInput = localInput * 2 return localInput }
  17. func double(input: Int) -> Int { var input = input

    input = input * 2 return input } Name Shadowing
  18. func double(input: Int) -> Int { var input = input

    input = input * 2 return input }
  19. func noEscape(@noescape f: () -> ()) {} func example(inout x:

    Int) { noEscape { _ = x } } safe because @noescape => closure can't be called after function returns
  20. func escape(f: () -> ()) {} func example(inout x: Int)

    { escape {[x] in _ = x } } [x] is a capture list a constant is initialized to have the value of x
  21. func curried(x: Int)(y: Int) -> Int { return {(y: Int)

    -> Int in return x * y } } curried(7)(8)
  22. func curried(x: Int)(y: Int) -> Int { return {(y: Int)

    -> Int in return x * y } } curried(7)(8)
  23. func curried(x: Int)(y: Int) -> Int { return {(y: Int)

    -> Int in return x * y } } curried(7)(8)
  24. func curried(x: Int)(y: Int) -> Int { return {(y: Int)

    -> Int in return x * y } } curried(7)(8)
  25. func curried(x: Int)(y: Int) -> Int { return {(y: Int)

    -> Int in return x * y } } curried(7)(8) 7 * y
  26. func curried(x: Int)(y: Int) -> Int { return {(y: Int)

    -> Int in return x * y } } curried(7)(8) 7 * 8
  27. func curried(x: Int)(y: Int) -> Int { return {(y: Int)

    -> Int in return x * y } } curried(7)(8)
  28. func curried(x: Int)(y: Int) -> Int { return {(y: Int)

    -> Int in return x * y } } curried(7)(8)
  29. func curried(x: Int)(y: Int) -> Int { return {(y: Int)

    -> Int in return x * y } } curried(7)(8)
  30. func curried(x: Int) -> (y: Int) -> Int { return

    {(y: Int) -> Int in return x * y } } curried(7)(8)
  31. func curried(x: Int) -> (y: Int) -> Int { return

    {(y: Int) -> Int in return x * y } } curried(7)(8)
  32. func curried(x: Int) -> (y: Int) -> Int { return

    {(y: Int) -> Int in return x * y } } curried(7)(8)
  33. func curried(x: Int) -> (y: Int) -> Int { return

    {(y: Int) -> Int in return x * y } } curried(7)(8)
  34. func curried(x: Int) -> (y: Int) -> Int { return

    {(y: Int) -> Int in return x * y } } curried(7)(8)
  35. class MyClass : NSObject { func callbackMethod(with notification: NSNotification){} func

    setNotification() { let center = NSNotificationCenter.defaultCenter() center .addObserver(self, selector: "callbackMethod", name: NSApplicationWillResignActiveNotification, object: NSApplication.sharedApplication()) } }
  36. class MyClass : NSObject { func callbackMethod(with notification: NSNotification){} func

    setNotification() { let center = NSNotificationCenter.defaultCenter() center .addObserver(self, selector: "callbackMethod", name: NSApplicationWillResignActiveNotification, object: NSApplication.sharedApplication()) } }
  37. class MyClass : NSObject { func callbackMethod(with notification: NSNotification){} func

    setNotification() { let center = NSNotificationCenter.defaultCenter() center .addObserver(self, selector: "callbackMethod", name: NSApplicationWillResignActiveNotification, object: NSApplication.sharedApplication()) } }
  38. class MyClass : NSObject { func callbackMethod(with notification: NSNotification){} func

    setNotification() { let center = NSNotificationCenter.defaultCenter() center .addObserver(self, selector: "callbackMethod", name: NSApplicationWillResignActiveNotification, object: NSApplication.sharedApplication()) } }
  39. class MyClass : NSObject { func callbackMethod(with notification: NSNotification){} func

    setNotification() { let center = NSNotificationCenter.defaultCenter() center .addObserver(self, selector: "callbackMethod", name: NSApplicationWillResignActiveNotification, object: NSApplication.sharedApplication()) } }
  40. class MyClass : NSObject { func callbackMethod(with notification: NSNotification){} func

    setNotification() { let center = NSNotificationCenter.defaultCenter() center .addObserver(self, selector: "callbackMethod", name: NSApplicationWillResignActiveNotification, object: NSApplication.sharedApplication()) } }
  41. class MyClass : NSObject { func callbackMethod(with notification: NSNotification){} func

    setNotification() { let center = NSNotificationCenter.defaultCenter() center .addObserver(self, selector: #selector(callbackMethod), name: NSApplicationWillResignActiveNotification, object: NSApplication.sharedApplication()) } }
  42. class MyClass : NSObject { func callbackMethod(with notification: NSNotification){} func

    setNotification() { let center = NSNotificationCenter.defaultCenter() center .addObserver(self, selector: #selector(MyClass.callbackMethod), name: NSApplicationWillResignActiveNotification, object: NSApplication.sharedApplication()) } }
  43. class MyClass : NSObject { func callbackMethod(){} func callbackMethod(with notification:

    NSNotification){} func setNotification() { let center = NSNotificationCenter.defaultCenter() center .addObserver(self, selector: #selector(MyClass.callbackMethod), name: NSApplicationWillResignActiveNotification, object: NSApplication.sharedApplication()) } }
  44. class MyClass : NSObject { func callbackMethod(){} func callbackMethod(with notification:

    NSNotification){} func setNotification() { let center = NSNotificationCenter.defaultCenter() center .addObserver(self, selector: #selector(MyClass.callbackMethod), name: NSApplicationWillResignActiveNotification, object: NSApplication.sharedApplication()) } }
  45. class MyClass : NSObject { func callbackMethod(){} func callbackMethod(with notification:

    NSNotification){} func setNotification() { let center = NSNotificationCenter.defaultCenter() center .addObserver(self, selector: #selector(MyClass.callbackMethod(with:)), name: NSApplicationWillResignActiveNotification, object: NSApplication.sharedApplication()) } }
  46. HK_EXTERN NSString * const HKQuantityTypeIdentifierBodyMassIndex; HK_EXTERN NSString * const HKQuantityTypeIdentifierBodyFatPercentage;

    HK_EXTERN NSString * const HKQuantityTypeIdentifierHeight; HK_EXTERN NSString * const HKQuantityTypeIdentifierBodyMass; HK_EXTERN NSString * const HKQuantityTypeIdentifierLeanBodyMass;
  47. HK_EXTERN NSString * const HKQuantityTypeIdentifierBodyMassIndex; HK_EXTERN NSString * const HKQuantityTypeIdentifierBodyFatPercentage;

    HK_EXTERN NSString * const HKQuantityTypeIdentifierHeight; HK_EXTERN NSString * const HKQuantityTypeIdentifierBodyMass; HK_EXTERN NSString * const HKQuantityTypeIdentifierLeanBodyMass;
  48. HK_EXTERN NSString * const HKQuantityTypeIdentifierBodyMassIndex; HK_EXTERN NSString * const HKQuantityTypeIdentifierBodyFatPercentage;

    HK_EXTERN NSString * const HKQuantityTypeIdentifierHeight; HK_EXTERN NSString * const HKQuantityTypeIdentifierBodyMass; HK_EXTERN NSString * const HKQuantityTypeIdentifierLeanBodyMass;
  49. enum Currency { case dollars case euros case pounds case

    yen var symbol: String { switch self { case dollars: return "$" default: return "I don't know" } } }
  50. enum Currency { case dollars case euros case pounds case

    yen var symbol: String { switch self { case .dollars: return "$" default: return "I don't know" } } }
  51. enum Currency { case dollars case euros case pounds case

    yen var symbol: String { switch self { case dollars: return "$" default: return "I don't know" } } }
  52. enum Currency { case dollars case euros case pounds case

    yen var symbol: String { switch self { case .dollars: return "$" default: return "I don't know" } } }
  53. enum Currency { case dollars case euros case pounds case

    yen var symbol: String { switch self { case .dollars: return "$" default: return "I don't know" } } }
  54. enum MyEnum { case case1(Int,Float) case case2(Float,Int) } switch value

    { case let .case1(x, 2), let .case2(2, x): print(x) case .case1, .case2: break }
  55. enum MyEnum { case case1(Int,Float) case case2(Float,Int) } switch value

    { case let .case1(x, 2), let .case2(2, x): print(x) case .case1, .case2: break }
  56. enum MyEnum { case case1(Int,Float) case case2(Float,Int) } switch value

    { case let .case1(x, 2), let .case2(2, x): print(x) case .case1, .case2: break }
  57. enum MyEnum { case case1(Int,Float) case case2(Float,Int) } switch value

    { case let .case1(x, 2), let .case2(2, x): print(x) case .case1, .case2: break }
  58. enum MyEnum { case case1(Int,Float) case case2(Float,Int) } switch value

    { case let .case1(x, 2), let .case2(2, x): print(x) case .case1, .case2: break }
  59. enum MyEnum { case case1(Int,Float) case case2(Float,Int) } switch value

    { case let .case1(x, 2), let .case2(2, x): print(x) case .case1, .case2: break }
  60. enum MyEnum { case case1(Int,Float) case case2(Float,Int) } switch value

    { case let .case1(x, 2), let .case2(2, x): print(x) case .case1, .case2: break }
  61. struct Friend { let name: String let location: String func

    nameBadge() { print("I'm", name, "from", location) } }
  62. struct Friend { let name: String let location: String func

    nameBadge() { print("I'm", name, "from", location) } }
  63. struct Friend { let name: String let location: String func

    nameBadge() { print("I'm", name, "from", location) } }
  64. struct Friend { let name: String let location: String func

    nameBadge() { print("I'm", self.name, "from", self.location) } }
  65. struct Friend { let name: String let location: String func

    nameBadge() { print("I'm", self.name, "from", self.location) } } Require self for accessing instance members REJECTED
  66. protocol Prot { typealias Container : SequenceType } extension Prot

    { typealias Element = Container.Generator.Element }
  67. protocol Prot { typealias Container : SequenceType } extension Prot

    { typealias Element = Container.Generator.Element }
  68. protocol Prot { associatedtype Container : SequenceType } extension Prot

    { typealias Element = Container.Generator.Element }
  69. func sum<T: Sequence where T.Element == Int>(sequence: T) -> Int

    { return sequence.reduce(0, combine: +) }
  70. extension Sequence { typealias Element = Iterator.Element func concat(other: Self)

    -> [Element] { return Array<Element>(self) + Array<Element>(other) } }
  71. extension Sequence { typealias Element = Iterator.Element func concat(other: Self)

    -> [Element] { return Array<Element>(self) + Array<Element>(other) } }
  72. typealias StringDictionary<T> = Dictionary<String, T> typealias DictionaryOfStrings<T : Hashable> =

    Dictionary<T, String> typealias IntFunction<T> = (T) -> Int typealias Vec3<T> = (T, T, T) typealias BackwardTriple<T1,T2,T3> = (T3, T2, T1)
  73. typealias StringDictionary<T> = Dictionary<String, T> typealias DictionaryOfStrings<T : Hashable> =

    Dictionary<T, String> typealias IntFunction<T> = (T) -> Int typealias Vec3<T> = (T, T, T) typealias BackwardTriple<T1,T2,T3> = (T3, T2, T1)
  74. typealias StringDictionary<T> = Dictionary<String, T> typealias DictionaryOfStrings<T : Hashable> =

    Dictionary<T, String> typealias IntFunction<T> = (T) -> Int typealias Vec3<T> = (T, T, T) typealias BackwardTriple<T1,T2,T3> = (T3, T2, T1)
  75. typealias StringDictionary<T> = Dictionary<String, T> typealias DictionaryOfStrings<T : Hashable> =

    Dictionary<T, String> typealias IntFunction<T> = (T) -> Int typealias Vec3<T> = (T, T, T) typealias BackwardTriple<T1,T2,T3> = (T3, T2, T1)
  76. typealias StringDictionary<T> = Dictionary<String, T> typealias DictionaryOfStrings<T : Hashable> =

    Dictionary<T, String> typealias IntFunction<T> = (T) -> Int typealias Vec3<T> = (T, T, T) typealias BackwardTriple<T1,T2,T3> = (T3, T2, T1)