Realm = RLMRealm 'has no member setDefaultRealmPath'

I added Realm.framework and RealSwift.framework to the project. and "import Realm", although I get 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 that I don't seem to see in this solution anywhere, being so new.

Thanks in advance.

+5
source share
3 answers

Realm (both Swift and Objective-C libraries) has been updated to version 0.97. Although setDefaultRealmPath was a valid API in the past, it was subsequently deprecated and completely removed from 0.97. Thus, if it worked in the past, after upgrading to 0.97 it will now result in a build error.

Realm file configuration is now controlled using Realm RLMRealmConfiguration objects. To set the default path, you should 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 more clarification!

+9
source

A new way to change the default Realm path:

 let directory: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.YOUR_BUNDLE_ID")! let realmPath = directory.path.appending("db.realm") let configuration = RLMRealmConfiguration.default() configuration.pathOnDisk = realmPath RLMRealmConfiguration.setDefault(configuration) 
+2
source

In Swift 4 you can use this

 let identifier = "group.companyName.projectName" var directory: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: identifier)! directory.appendPathComponent("db.realm", isDirectory: true) let config = Realm.Configuration( fileURL: directory, schemaVersion: 1, migrationBlock: { migration, oldSchemaVersion in }) Realm.Configuration.defaultConfiguration = config 
0
source

Source: https://habr.com/ru/post/1239010/


All Articles