This repository was archived by the owner on Nov 8, 2021. It is now read-only.
Description Goals
Migrate local realm to cloud
Expected Results
Sample code should compile
Actual Results
It seems the sample code is using outdated API's
#import "AppDelegate.h"
@import Realm;
@import Realm.Dynamic;
@import Realm.Private;
@interface AppDelegate ()
@EnD
@implementation AppDelegate
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *sourceFilePath = [[NSBundle mainBundle] pathForResource:@"fieldFlow" ofType:@"realm"];
RLMRealmConfiguration *configuration = [[RLMRealmConfiguration alloc] init];
configuration.fileURL = [NSURL URLWithString:sourceFilePath];
configuration.dynamic = true;
configuration.readOnly = YES;
RLMRealm *localRealm = [RLMRealm realmWithConfiguration:configuration error:nil];
RLMSyncCredentials *creds = [RLMSyncCredentials credentialsWithUsername:@"admin@realm.io " password:@"password" register:NO];
[RLMSyncUser logInWithCredentials:creds authServerURL:[NSURL URLWithString:@"http://localhost:9080"] onCompletion:^(RLMSyncUser *syncUser, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[self copyToSyncRealmWithRealm: localRealm user:syncUser];
});
}];
return YES;
}
(void)copyToSyncRealmWithRealm:(RLMRealm *)realm user:(RLMSyncUser *)user
{
RLMRealmConfiguration *syncConfig = [[RLMRealmConfiguration alloc] init];
syncConfig.syncConfiguration = [[RLMSyncConfiguration alloc] initWithUser:user realmURL:[NSURL URLWithString:@"realm://localhost:9080/~/fieldRow"]];
syncConfig.customSchema = [realm.schema copy];
RLMRealm *syncRealm = [RLMRealm realmWithConfiguration:syncConfig error:nil];
syncRealm.schema = syncConfig.customSchema;
[syncRealm transactionWithBlock:^{
NSArray *objectSchema = syncConfig.customSchema.objectSchema;
for (RLMObjectSchema *schema in objectSchema) {
RLMResults *allObjects = [realm allObjects:schema.className];
for (RLMObject *object in allObjects) {
RLMCreateObjectInRealmWithValue(syncRealm, schema.className, object, true);
}
}
}];
}
@EnD
Would someone mind updating the documentation to reflect the current APIs.
Reactions are currently unavailable
Goals
Migrate local realm to cloud
Expected Results
Sample code should compile
Actual Results
It seems the sample code is using outdated API's
#import "AppDelegate.h"
@import Realm;
@import Realm.Dynamic;
@import Realm.Private;
@interface AppDelegate ()
@EnD
@implementation AppDelegate
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *sourceFilePath = [[NSBundle mainBundle] pathForResource:@"fieldFlow" ofType:@"realm"];
RLMRealmConfiguration *configuration = [[RLMRealmConfiguration alloc] init];
configuration.fileURL = [NSURL URLWithString:sourceFilePath];
configuration.dynamic = true;
configuration.readOnly = YES;
RLMRealm *localRealm = [RLMRealm realmWithConfiguration:configuration error:nil];
RLMSyncCredentials *creds = [RLMSyncCredentials credentialsWithUsername:@"admin@realm.io" password:@"password" register:NO];
[RLMSyncUser logInWithCredentials:creds authServerURL:[NSURL URLWithString:@"http://localhost:9080"] onCompletion:^(RLMSyncUser *syncUser, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[self copyToSyncRealmWithRealm: localRealm user:syncUser];
});
}];
return YES;
}
(void)copyToSyncRealmWithRealm:(RLMRealm *)realm user:(RLMSyncUser *)user
{
RLMRealmConfiguration *syncConfig = [[RLMRealmConfiguration alloc] init];
syncConfig.syncConfiguration = [[RLMSyncConfiguration alloc] initWithUser:user realmURL:[NSURL URLWithString:@"realm://localhost:9080/~/fieldRow"]];
syncConfig.customSchema = [realm.schema copy];
RLMRealm *syncRealm = [RLMRealm realmWithConfiguration:syncConfig error:nil];
syncRealm.schema = syncConfig.customSchema;
[syncRealm transactionWithBlock:^{
NSArray *objectSchema = syncConfig.customSchema.objectSchema;
for (RLMObjectSchema *schema in objectSchema) {
RLMResults *allObjects = [realm allObjects:schema.className];
for (RLMObject *object in allObjects) {
RLMCreateObjectInRealmWithValue(syncRealm, schema.className, object, true);
}
}
}];
}
@EnD
Would someone mind updating the documentation to reflect the current APIs.