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

The Old and the New

The Old and the New

There is little questioning that Swift is where we’re headed, but for the time being it’s important to be pragmatic about interoperability with Cocoa and existing code is in order to remain productive.

This talk is about how our team uses Swift, how we approach new language features and functional patterns (the new), and how we deal with both Cocoa and other existing code (the old).

David Rönnqvist

March 20, 2016
Tweet

More Decks by David Rönnqvist

Other Decks in Programming

Transcript

  1. ! "

  2. AnyBidirectionalCollection AnyBidirectionalIndex AnyForwardCollection AnyForwardIndex AnyRandomAccessCollection AnyRandomAccessIndex AnySequence Array ArraySlice AutoreleasingUnsafeMutablePointer

    Bool COpaquePointer CVaListPointer Character ClosedInterval CollectionOfOne ContiguousArray Dictionary DictionaryGenerator DictionaryIndex DictionaryLiteral Double EmptyCollection EmptyGenerator EnumerateGenerator EnumerateSequence FlattenBidirectionalCollection FlattenBidirectionalCollectionIndex FlattenCollection FlattenCollectionIndex FlattenGenerator FlattenSequence Float GeneratorOfOne GeneratorSequence HalfOpenInterval IndexingGenerator Int Int16 Int32 Int64 Int8 JoinGenerator JoinSequence LazyCollection LazyFilterCollection LazyFilterGenerator LazyFilterIndex LazyFilterSequence LazyMapCollection LazyMapGenerator LazyMapSequence LazySequence ManagedBufferPointer Mirror MutableSlice ObjectIdentifier PermutationGenerator Range RangeGenerator RawByte Repeat ReverseCollection ReverseIndex ReverseRandomAccessCollection ReverseRandomAccessIndex Set SetGenerator SetIndex Slice StaticString StrideThrough StrideThroughGenerator StrideTo StrideToGenerator String String.CharacterView String.CharacterView.Index String.UTF16View String.UTF16View.Index String.UTF8View String.UTF8View.Index String.UnicodeScalarView String.UnicodeScalarView.Generator String.UnicodeScalarView.Index UInt UInt16 UInt32 UInt64 UInt8 UTF16 UTF32 UTF8 UnicodeScalar Unmanaged UnsafeBufferPointer UnsafeBufferPointerGenerator UnsafeMutableBufferPointer UnsafeMutablePointer UnsafePointer Zip2Generator Zip2Sequence Bit FloatingPointClassification ImplicitlyUnwrappedOptional Mirror.AncestorRepresentation Mirror.DisplayStyle Optional PlaygroundQuickLook Process UnicodeDecodingResult AnyGenerator NonObjectiveCBase ManagedProtoBuffer ManagedBuffer VaListBuilder Structs Enums Classes
  3. %

  4. no client should be forced to depend on methods it

    does not use “interface-segregation principle”
  5. “kärt barn har många namn” something which is liked or

    well though of, is often referred to by many different names
  6. &

  7. T?

  8. ([A], (A  B))  [B] 1 2 3 4

    5 6 7 8 1 4 9 16 25 36 49 64 square square square square square square square square
  9. ([A], (A  Bool))  [A] 1 2 3 4

    5 6 7 8 isPrime isPrime isPrime isPrime isPrime isPrime isPrime isPrime 3 5 7 2
  10. infix operator ⚬ { associativity left precedence 160 } func

    ⚬ <A, B, C>(f: B -> C, g: A -> B) -> (A -> C) { return { x in f(g(x)) } }
  11. ([A], B, ((B, A)  B))  B 0 1

    2 3 4 5 7 8 + 1 + 5 + 12 + 20 + 23 + 28 + 30
  12. A B C D E F G H 1 2

    3 4 5 6 7 0 enumerate
  13. A B C D E F G H 1 4

    9 16 25 36 49 64 zip
  14. 3 6 9 12 15 18 21 24 0 0.5

    1.0 1.5 2.0 2.5 3.0 3.5 4.0 0.0 stride
  15. '

  16. for (dot, config) in zip(dots, dotConfigs) { let move =

    CAKeyframeAnimation(keyPath: "position") move.path = circularPath() move.timingFunction = config.rotationTimingFunction let scale = CAKeyframeAnimation(keyPath: “transform.scale") scale.values = config.scaleValues scale.keyTimes = config.scaleKeyTimes scale.timingFunctions = config.scalingTimingFunctions let group = CAAnimationGroup() group.duration = 1.4 group.repeatCount = HUGE group.animations = [move, scale] dot.addAnimation(group, forKey: nil) }
  17. func testChange_whenRemovingMiddleElement_shouldLeaveMiddleEmpty() { let (slots, _) = setupTestData("A B C",

    history: "ABC") let (newSlots, change) = slots.removing("B") XCTAssertEqual(newSlots.testSummary, "A _ C") XCTAssertEqual(change, SlotChange.Removal(at: 1)) } // ... func testAddingElementTwice_shouldNotTriggerAnyKVO() { sut.add("A") expectNoObservationFor { sut.add("A") } } func testAddingElement_whenFullAndMiddleIsOldest_shouldHaveKVOReplacementAtMiddle() { sut.add("A") sut.add("B") sut.add("A") sut.add("C") expectObservationFor(.Replacement(at: 1)) { sut.add("D") } }
  18. A language that doesn't affect the way you think about

    programming, is not worth knowing. Alan Perlis first recipient of the Turing Award “ ”