Our issues in iOS development Massive delegate pattern Complex https://developer.apple.com/library/content/documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html Apple MVC Apple MVC
Reactive program paradigm Observable Asynchronous data streams Functional program paradigm No side effects function Immutable structure Higher-order functions Lambda expression, monads Asynchronous friendly Unidirectional Data Flow Single source of truth The approach avoids complicated to simplify Redux RxSwift Reactive Cocoa simplify
Launch iPhone3G iOS Developer since mid 2008 Realm Notification Notifications section https://realm.io/docs/swift/latest/#notifications Collection Notifications, since ver 0.98 https://realm.io/news/realm-objc-swift-0.98.0/ Fine-grained change notifications, since ver 0.99 https://realm.io/news/realm-objc-swift-0.99.0/
Launch iPhone3G iOS Developer since mid 2008 You can be notified whenever a Realm, Results, List or LinkingObjects is updated by calling the addNotificationBlock method. a.k.a. Observe What Realm Notification
Launch iPhone3G iOS Developer since mid 2008 Realm instances send out notifications to other instances on other threads every time a write transaction is committed: Realm Notifications
Launch iPhone3G iOS Developer since mid 2008 Fine-grained level changing This change parameter describes including the indices of objects that have been inserted, deleted, or modified since the last notification.
Launch iPhone3G iOS Developer since mid 2008 In the case of Core Data let notificationCenter = NSNotificationCenter.defaultCenter() notificationCenter.addObserver(self, selector: #selector(managedObjectContextDidChange:), name: NSManagedObjectContextObjectsDidChangeNotification, object: privateManagedObjectContext) Can not observe with filtering.
Launch iPhone3G iOS Developer since mid 2008 In the case of Core Data func managedObjectContextObjectsDidChange(notification: NSNotification) { guard let userInfo = notification.userInfo else { return } if let inserts = userInfo[NSInsertedObjectsKey] as? Set where inserts.count > 0 { } if let updates = userInfo[NSUpdatedObjectsKey] as? Set where updates.count > 0 { } if let deletes = userInfo[NSDeletedObjectsKey] as? Set where deletes.count > 0 { } } Received changed objects, instead of changed indices
Launch iPhone3G iOS Developer since mid 2008 Notified timing When notifications can’t be delivered instantly, multiple write transactions may be coalesced into a single notification. t Tx COMMIT Tx COMMIT Tx COMMIT Tx COMMIT Tx COMMIT t Notice Notice Write Notification
Launch iPhone3G iOS Developer since mid 2008 It is also notified being monitored relation destination of the change of the Object. Observable relations ( linking objects )
Launch iPhone3G iOS Developer since mid 2008 Model View B View A Notification Notification WriteTx Absolutely separation logic and views Singleton PreFetch BackgroundFetch
Launch iPhone3G iOS Developer since mid 2008 View ViewModel View A Subscribe Holding - The state of a screen-specific (Requesting, etc) - The main data of a screen RxSwift w/ MVVM It is difficult to handle the screen cross-data. View B View C
Launch iPhone3G iOS Developer since mid 2008 View ViewModel Subscribe Singleton RxSwift w/ MVVM and Singleton Global ViewModel View A View B View C Holding - The state of a screen-specific (Requesting, etc) - The main data of a screen (Rx Variable) The state of cross over screens
Launch iPhone3G iOS Developer since mid 2008 View ViewModel Observable Store Subscribe The state of a screen-specific Singleton RxSwift+RxRealm w/ MVVM (RxRealm) View A View B View C (Rx Variable) The main data of screens The state of cross over screens