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
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/
of Core Data let notificationCenter = NSNotificationCenter.defaultCenter() notificationCenter.addObserver(self, selector: #selector(managedObjectContextDidChange:), name: NSManagedObjectContextObjectsDidChangeNotification, object: privateManagedObjectContext) Can not observe with filtering.
of Core Data func managedObjectContextObjectsDidChange(notification: NSNotification) { guard let userInfo = notification.userInfo else { return } if let inserts = userInfo[NSInsertedObjectsKey] as? Set<NSManagedObject> where inserts.count > 0 { } if let updates = userInfo[NSUpdatedObjectsKey] as? Set<NSManagedObject> where updates.count > 0 { } if let deletes = userInfo[NSDeletedObjectsKey] as? Set<NSManagedObject> where deletes.count > 0 { } } Received changed objects, instead of changed indices
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
to Results, List, LinkingObjects and AnyRealmCollection these methods: - asObservable() - asObservableArray() - asObservableChangeset() - asObservableArrayChangeset() returning an Observable<Array<T>, RealmChangeset?>
MessageRealm("world")] .toObservable() .subscribe(Realm.rx_add()) // With API let request = API.Endpoint.MessagesRequest().request() Session.rx_response(request) .subscribe(Realm.rx_add())
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
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
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