Comments (4)
Hi Dan, this feature is very high on our priority list. Internally, we call it "fine grain notifications".
Until this feature is released, you could achieve many of the same results by keeping an NSDictionary of changes as they happen. For example:
@interface ToDoItem : RLMObject
@property NSString *uuid;
@property NSString *name;
@end
@implementation ToDoItem : RLMObject
@end
@interface ToDoListViewController : UITableViewController
@property (nonatomic, strong) RLMRealm *realm;
@property (nonatomic, strong) NSMutableDictionary *changes;
@end
@implementation ToDoListViewController : UITableViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Set realm notification block
__weak typeof(self) weakSelf = self;
[RLMRealm.defaultRealm addNotificationBlock:^(NSString *note, RLMRealm *realm) {
NSLog(@"added: %@\nremoved: %@", weakSelf.changes[@"added"], weakSelf.changes[@"removed"]);
// Process changes (animate insertions, deletions, reorderings, etc.)
weakSelf.changes = [NSMutableDictionary dictionary]; // reset the changes dictionary
}];
}
- (void)addTodoItemWithName:(NSString *)name {
[self.realm beginWriteTransaction];
ToDoItem *todoItem = [ToDoItem new];
todoItem.name = name;
todoItem.uuid = [[NSUUID UUID] stringValue];
[self.realm addObject:todoItem];
[self.realm commitWriteTransaction];
[changes[@"added"] addObject:todoItem.uuid];
}
- (void)removeItemWithUUID:(NSString *)uuid {
[realm beginWriteTransaction];
[realm deleteObject:[[ToDoItem objectsWhere:@"uuid == %@", uuid] firstObject]];
[realm commitWriteTransaction];
[changes[@"removed"] addObject:uuid];
}
@end
Note that this is a contrived example, but it should give you a sense of the approach. If there are several threads reading/writing to the realm simultaneously, you'd need to be a little safer with how you use the changes NSMutableDictionary.
from realm-swift.
Great, thanks for the response. Do you think "fine grain notifications" will make it into the 1.0 release?
from realm-swift.
Certainly.
from realm-swift.
Brilliant! Thanks!
from realm-swift.
Related Issues (20)
- Apple Privacy Manifest - Realm 10.49.2 - ISSUE: NSPrivacyAccessedAPICategoryDiskSpace HOT 9
- Add Apple Privacy Manifests to a 10.48.2 Release HOT 6
- Realm Corruption Following Client Resets Due to Permission/Role Changes on Server HOT 5
- Drop support for Xcode 14 HOT 1
- Crash After 10.49.3 Update Due to Missing Framework HOT 6
- v10.49.3 failing to Build after updating using SPM.error: "but cannot be built dynamically because there is a package product with the same name." HOT 11
- Updating RealmSwift to latest version doesn't update realm-core to the latest HOT 2
- Crash ITMS-90863: Macs with Apple silicon support issue HOT 6
- skipping cache due to an error: https://github.com/realm/realm-swift: The repository could not be found. Make sure a valid repository exists at the specified location and try again. HOT 2
- Error loading RealmSwift dynamic framework in macOS app HOT 4
- SDKs should not consume stitch_ prefixed fields HOT 1
- v10.49.3 crashing when Embed & Signing a RealmSwift that is not the main target HOT 1
- terminating due to uncaught exception of type realm::util::DecryptionFailed: Decryption failed: 'unable to decrypt after 0 seconds (retry_count=2, from=iv1 == 0, size=16384) HOT 2
- Realm Swift 10.50.0 fails to build HOT 5
- Terminating app due to uncaught exception 'RLMException', reason: 'Attempting to modify object outside of a write transaction - call begin Write Transaction on an RLMRealm instance first HOT 1
- Realm 10.50.0 Cocoapods compile warning HOT 5
- Xcode15 Realm crash HOT 2
- Version 10.47.0 AppStore Connect issues: ITMS-91065: Missing signature HOT 8
- Database has an unsupported version (24) and cannot be upgraded. HOT 9
- 'RealmSwiftObject' is not a member type of struct 'RealmSwift.Realm' HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from realm-swift.