Search code examples
iosswift2realmxcode7.2

Realm = RLMRealm' has no member 'setDefaultRealmPath'


I have added the Realm.framework and RealSwift.framework to a project. and "import Realm" though I'm getting this error:

RLMRealm' has no member 'setDefaultRealmPath'

 let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.it.fancypixel.Done")!
        let realmPath = (directory.path! as NSString).stringByAppendingPathComponent("db.realm")
        RLMRealm.setDefaultRealmPath(realmPath)

Any ideas I can't seem to see a solution for this anywhere being it's so new.

Thanks in advance.


Solution

  • Realm (Both the Swift and Objective-C libraries) was just updated to version 0.97. While setDefaultRealmPath was a valid API in the past, it was subsequently deprecated, and as of 0.97, completely removed. As such, if it was working in the past, once you've updated to 0.97, it will now result in a build error.

    Setting the file location of a Realm is now controlled via Realm RLMRealmConfiguration objects. To set the default path, you would now do it like this:

    let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.it.fancypixel.Done")!
    let realmPath = (directory.path! as NSString).stringByAppendingPathComponent("db.realm")
    
    var config = RLMRealmConfiguration.defaultConfiguration()
    config.path = realmPath
    RLMRealmConfiguration.setDefaultConfiguration(config)
    

    Let me know if you need any more clarification!