Lê Khánh Vinh Lê Khánh Vinh - 1 year ago 128
iOS Question

+[RLMRealm setDefaultRealmPath:] not found when upgrading from old version of Realm

I'm upgrading my Objective-C project to a newer version of Realm but am having some problems. The code below works with the version of Realm I was using, but not with the new version:

+ (void)setupRealm {
NSURL *realmURL = [[NSFileManager defaultManager]containerURLForSecurityApplicationGroupIdentifier:APP_GROUP_ID];
NSString *realmPath = [realmURL.path stringByAppendingPathComponent:@"SingPost.realm"];

[RLMRealm setDefaultRealmPath:realmPath];
NSLog(@"Default Realm Path : %@",[RLMRealm defaultRealmPath]);

The error is:


How can I set the default Realm path in new versions of Realm?

Answer Source

+[RLMRealm defaultRealmPath] / +[RLMRealm setDefaultRealmPath:] were deprecated in Realm v0.95.0, released nearly a year ago, and have since been removed. They were replaced by the fileURL property on the RLMRealmConfiguration class.

+ (void)setupRealm {
    NSURL *containerURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:APP_GROUP_ID];
    NSURL *realmURL = [containerURL URLByAppendingPathComponent:@"SingPost.realm"];

    RLMRealmConfiguration *configuration = [RLMRealmConfiguration defaultConfiguration];
    configuration.fileURL = realmURL;
    [RLMRealmConfiguration setDefaultConfiguration:configuration];

    NSLog(@"Default Realm location: %@", realmURL);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download