Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. @interface ModelA : RLMObject
  2. @property int pk;
  3. @end
  4.  
  5. @implementation ModelA
  6. + (NSString *) primaryKey
  7. {
  8. return @"pk";
  9. }
  10. @end
  11.  
  12. @implementation ViewController
  13. {
  14. RLMNotificationToken *_nfA;
  15. }
  16.  
  17. - (void)viewDidLoad
  18. {
  19. [super viewDidLoad];
  20. RLMRealm *realm = [RLMRealm defaultRealm];
  21.  
  22. [realm beginWriteTransaction];
  23. for(int i = 0; i<10; ++i)
  24. {
  25. ModelA *a = [[ModelA alloc] init];
  26. a.pk = i;
  27. [realm addOrUpdateObject:a];
  28. }
  29. [realm commitWriteTransaction];
  30.  
  31. _nfA = [[ModelA allObjects] addNotificationBlock:^(RLMResults *results, RLMCollectionChange *change, NSError *error)
  32. {
  33. if(change)
  34. {
  35. NSLog(@"Insertions: %lu deleteions:%lu modifications:%lun", change.insertions.count, change.deletions.count, change.modifications.count);
  36. }
  37. }];
  38.  
  39. for(int i=0; i<10; ++i)
  40. {
  41. RLMRealm *realm = [RLMRealm defaultRealm];
  42. [realm beginWriteTransaction];
  43. [realm deleteObject:[[ModelA allObjects] objectAtIndex:0]];
  44. [realm commitWriteTransaction];
  45. }
  46. }
  47. @end
  48.  
  49. 2017-01-20 10:44:19.394 Test[7536:12871658] Insertions: 1 deleteions:2 modifications:0
  50. 2017-01-20 10:44:19.395 Test[7536:12871658] Insertions: 1 deleteions:2 modifications:0
  51. 2017-01-20 10:44:19.395 Test[7536:12871658] Insertions: 1 deleteions:2 modifications:0
  52. 2017-01-20 10:44:19.396 Test[7536:12871658] Insertions: 1 deleteions:2 modifications:0
  53. 2017-01-20 10:44:19.396 Test[7536:12871658] Insertions: 1 deleteions:2 modifications:0
  54. 2017-01-20 10:44:19.397 Test[7536:12871658] Insertions: 1 deleteions:2 modifications:0
  55. 2017-01-20 10:44:19.397 Test[7536:12871658] Insertions: 1 deleteions:2 modifications:0
  56. 2017-01-20 10:44:19.397 Test[7536:12871658] Insertions: 1 deleteions:2 modifications:0
  57. 2017-01-20 10:44:19.398 Test[7536:12871658] Insertions: 0 deleteions:1 modifications:0
  58. 2017-01-20 10:44:19.402 Test[7536:12871658] Insertions: 0 deleteions:1 modifications:0
  59.  
  60. _nfA = [[[ModelA allObjects] sortedResultsUsingKeyPath:@"pk" ascending:NO] addNotificationBlock:...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement