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

Building Skype for Business in Swift

Building Skype for Business in Swift

Slides from a "Talking Tech with Microsoft" presentation I gave in Stockholm.

David Rönnqvist

June 30, 2016
Tweet

More Decks by David Rönnqvist

Other Decks in Programming

Transcript

  1. × ( ) ∶ → → , ↦ None Some

    ( ʹ) if = None if = Some ʹ ῲ ῳ ῴ ? ? × ( ) ∶ → → , ↦ None ( ʹ) if = None if = Some ʹ ῲ ῳ ῴ ? ? ?
  2. class MyExamplePerson: NSObject, IPAEventListener { let person: IPAExamplePerson init(person: IPAExamplePerson)

    { self.person = person super.init() // Register for events self.person.registerListener(self) } deinit { // Deregister for events self.person.deregisterListener(self) } // Check if the IPAPerson has updated it's display name @objc func onEvent(event: AnyObject!) { // Verify that it's the correct kind of event guard let personEvent = event as? IPAExamplePersonEvent else { return } // Verify that the event is for an updated property guard personEvent.type == .PropertiesChanged else { return } // Check that it was the expected property that changed if personEvent.isPropertyChanged(.DisplayName) { // get the new display name } } }
  3. typealias Callback = (Event) -> () private typealias Predicate =

    (Event) -> Bool private init( source: IPAEventListenerRegistry, predicatesAndCallbacks: [([Predicate], Callback)] )
  4. init(person: IPAExamplePerson) { self.person = person self.displayNameListener = EventListener(source: person,

    predicatesAndCallbacks: [ ([ // Event verifications { event in event.type == .PropertiesChanged }, { event in event.isPropertyChanged(.DisplayName) } ], // Callback { _ in // get the new display name } ) ] ) }
  5. private init( source: IPAEventListenerRegistry, predicatesAndCallbacks: [([Predicate], Callback)] ) private convenience

    init<T>( source: IPAEventListenerRegistry, transformableAndCallbacks: [(T, Callback)], transform: (T -> [Predicate]) )
  6. extension EventListener where E: PropertyEvent { convenience init( source: IPAEventListenerRegistry,

    forPropertyChange: (E.Property, EmptyCallback) ... ) } protocol PropertyEvent: Event { associatedtype Property func isPropertyChanged(property: Property) -> Bool }
  7. init(person: IPAExamplePerson) { self.person = person self.displayNameListener = EventListener(source: person,

    forPropertyChanges: (.DisplayName, { // get the new display name }) ) }
  8. KVO

  9. Owner {} KVO Target (collection) 1-way KVO Bindings on collections

    (automatically updating one collection when elements are added/removed in another collection)
  10. Owner KVO Target (collection) {} KVO KVO KVO KVO KVO

    {} 1-way KVO Bindings over collections (closure callbacks when elements are added/removed from the observed collection or when elements within the collection updates)