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

A Swift Approach To Data Binding

Kersten
November 18, 2015
450

A Swift Approach To Data Binding

Cocoaheads Berlin Talk 18.11.2015

Kersten

November 18, 2015
Tweet

Transcript

  1. A Swift Approach To Data Binding Cocoaheads Berlin, 18.11.2015 Kersten

    Broich
 (iOS Developer at Kitchen Stories)
 
 @kersten_broich
  2. Freestyle MVC Do what you want as long as a

    UIViewController is involved..
  3. Core Data – Soroush Khanlou “Core Data was designed before

    the prevalance of web services and APIs. It was intended to represent an object graph in its entirety, rather than a small portion that has been downloaded from a service. Since you don't have the whole dataset, you can't even effectively query against it.” http://khanlou.com/2015/07/cache-me-if-you-can/
  4. Core Data • Slow.. But not necessarily Core Data’s fault

    • Notifications, Synchronisation, Data consistency • Do we really need it with our use case? • Object graph is relatively simple
  5. Massive View Controllers • No clear architectural guidelines • Huge

    implementation files • Lots of undocumented dependencies • A big mess
  6. …but where to start? • Time for research (very important!)

    • Build little prototype projects that demonstrate the use of core technologies. • Discuss as a team and ask other’s for input • Document your decisions
  7. • Large Objective-C codebase (grown since ’13) • Swift is

    the future • It’s fun and it’s safe!
  8. Immutable Objects “One thing that a lot of us learned

    the hard way is that these (model) objects should be immutable.” Chris Eidhof https://www.objc.io/issues/7-foundation/value-objects/
  9. • Mutability is a source of bugs (Objects might change

    when you don’t expect changes) • Take every opportunity to reduce complexity (i.e. in multi-threaded contexts) • Swift makes immutability in models easy by just using ‘let’ Why?
  10. How do we define a Listener? Reference View Controller from

    a wrapping class Create a listener protocol and make listeners adopt to it
  11. How do we define a Listener? Reference View Controller from

    a wrapping class Create a listener protocol and make listeners adopt to it
  12. How do we define a Listener? Reference View Controller from

    a wrapping class Create a listener protocol and make listeners adopt to it Closure
  13. Wouldn’t it be nice if… • Listeners and therefor closures

    are not referenced within the encapsulated data type? • We could register multiple observers to a property? • We could unregister an observer from a property? • and all of that is thread-safe?
  14. • Event-Driven Data Binding framework in Swift • Abstract definition

    of an EventProducer type • Extension on UIKit components • Observing/Unobserving • Transforming Events • Bidirectional bindings
  15. The Observable
 (Dynamic) Encapsulates a value that can change and

    informs observers about that change The Event Producer
  16. View Model performs data update performs batch operations on the

    array and emits a batch operation event when ready. leverage fine-grained change set events