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

Share Data Across Extension and App with Realm

Share Data Across Extension and App with Realm

Share Data Across Extension and App with Realm

Kishikawa Katsumi

May 14, 2015
Tweet

More Decks by Kishikawa Katsumi

Other Decks in Programming

Transcript

  1. NSFileManager *fileManager = [[NSFileManager alloc] init]; NSURL *containerURL = [fileManager

    containerURLForSecurityApplicationGroupIdentifier:@"group.com.xxx.realm"]; NSString *containerPath = [containerURL URLByAppendingPathComponent:@"test.realm"].path; [RLMRealm setDefaultRealmPath:containerPath]; RLMRealm *realm = [RLMRealm defaultRealm]; [realm transactionWithBlock:^{ NSString *text = ...; __block NSUInteger identifier = 0; [text enumerateLinesUsingBlock:^(NSString *line, BOOL *stop) { Address *address = [[Address alloc] init]; address.address = line; [realm addObject:address]; }]; }];
  2. RLMRealm *realm = [RLMRealm defaultRealm]; [realm transactionWithBlock:^{ NSString *text =

    ...; __block NSUInteger identifier = 0; [text enumerateLinesUsingBlock:^(NSString *line, BOOL *stop) { Address *address = [[Address alloc] init]; address.address = line; [realm addObject:address]; }]; }]; NSFileManager *fileManager = [[NSFileManager alloc] init]; NSURL *containerURL = [fileManager containerURLForSecurityApplicationGroupIdentifier:@"group.com.xxx.realm"]; NSString *containerPath = [containerURL URLByAppendingPathComponent:@"test.realm"].path; RLMRealm *sharedRealm = [RLMRealm realmWithPath:containerPath]; [sharedRealm transactionWithBlock:^{ for (int i = 0; i < 10; i++) { Address *address = addresses[i]; Address *clone = [[Address alloc] initWithValue:address]; [sharedRealm addObject:clone]; } }];