Lê Khánh Vinh Lê Khánh Vinh - 2 months ago 13x
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?


+[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);