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

The latest info of ReactiveSwift and ReactiveCocoa

Sho Ikeda
September 16, 2017

The latest info of ReactiveSwift and ReactiveCocoa

iOSDC Japan 2017でのLT発表資料です #iosdc

https://iosdc.jp/2017/

Sho Ikeda

September 16, 2017
Tweet

More Decks by Sho Ikeda

Other Decks in Technology

Transcript

  1. RAC 5.0 • Repository Split • API Design • Signal

    • SignalProducer • Properties • Atomic • Others
  2. Repository Split • ReactiveSwift: 2.0 • ReactiveCocoa: 6.0 • ReactiveObjC:

    3.0 (Nullability Annotations, Lightweight Generics) • ReactiveObjCBridge: 2.0 (with RAS 2.0 and ReactiveObjC 3.0, Tuple Bridging)
  3. Signal • Safer Signal lifetime semantics: • #355 Revisit changes

    to the Signal lifetime semantics to improve tooling interoperability. • #463 Send interrupted when an input observer deinitializes. • Signal ʹΠϕϯτΛૹΓࠐΉinput observer͕อ࣋͞Εͳ͘ ͳͬͨΒ Signal ͕தஅʢഁغʣ͞ΕΔ • InstrumentsͰϝϞϦʔϦʔΫͱ൑அ͞Ε͍ͯͨՕॴΛղফ
  4. SignalProducer • SignalProducer resource management: • #334 Lifetime-based producer resource

    management • Before: SignalProducer<Int, NoError> { observer, disposable in guard disposable.isDisposed else { return } ... if someCondition { disposable.dispose() // Not desirable } }
  5. SignalProducer • SignalProducer resource management: • #334 Lifetime-based producer resource

    management • After: SignalProducer<Int, NoError> { observer, lifetime in guard lifetime.hasEnded else { return } ... if someCondition { observer.sendInterrupted() // Desirable } }
  6. SignalProducer • Reduced overhead for all SignalProducer lifted operators: •

    #140 Less hops in operator lifting. • ಺෦࣮૷ͷมߋͰύϑΥʔϚϯεվળ
  7. Disposables • SimpleDisposable and ActionDisposable has been folded into AnyDisposable:

    • #412 s/(ActionDisposable|SimpleDisposable)/ AnyDisposable/g • AnyDisposable ͷΠχγϟϥΠβʔҧ͍ʹ౷߹ AnyDisposable() // SimpleDisposable() AnyDisposable { ... } // ActionDisposable { ... }
  8. Swift 3.2+ • Smart KeyPaths support: • #435 Overload map()

    to support key paths let signal: Signal<String, NoError> let mapped = signal.map(\String.count) // Signal<Int, NoError> let mapped2 = signal.map { $0.count }
  9. Swift 3.2+ • Smart KeyPaths support: • #440 BindingTarget +

    Smart Key Paths. let target: BindingTarget<Int> = BindingTarget( lifetime: lifetime, object: object, keyPath: \.value ) let property = MutableProperty(1) target <~ property // object.value == 1 property.value = 2 // object.value == 2
  10. ReactiveCocoa • Foundation: Object Interception • Method Call Interception let

    appearing = viewController.reactive.trigger(for: #selector(UIViewController.viewWillAppear(_:))) • Object Lifetime object.reactive.lifetime.ended.observeCompleted(doCleanup) • Expressive, Safe Key Path Observation let producer = object.reactive.values(forKeyPath: #keyPath(key)) .take(during: self.reactive.lifetime) let property = DynamicProperty<String>(object: person, keyPath: #keyPath(person.name))
  11. ReactiveCocoa • AppKit & UIKit: UI bindings • UI Bindings:

    nameLabel.reactive.text <~ person.name • Controls and User Interactions preferences.allowsCookies <~ toggle.reactive.isOnValues textField.reactive.continuousTextValues.map { $0.characters.count } button.reactive.pressed = CocoaAction(viewModel.commit)
  12. ReactiveCocoa • Smart KeyPaths support • #3489 Reactive key path

    subscript. label.reactive[\.text] <~ viewModel.title