Closed bezpalyi closed 1 year ago
@bezpalyi In the code I cannot see the value to the path you are appending to your file url and this may be why you are getting an error, because is not a directory path "default.realm/auth.realm.lock". Any reason you want your path to be something like this `'/Users/iosdev/Library/Developer/CoreSimulator/Devices/AE6AAC4A-6494-417D-BED8-2A9EEEF448A2/data/Containers/Shared/AppGroup/0E73729C-85A4-412F-9051-D5DA7A88185B/default.realm/auth.realm.lock
Hi, @dianaafanador3
path
is auth.realm
in the above code.
let realmUrl = fileURL.appendingPathComponent(path)
Sorry I didn't ask before, why are you appending both "default.realm" and "auth.realm" to your file url. Any use cases for this, this is the reason why you may be getting an error. you need to use "default.realm" or "auth.realm"
Actually there are several realm dababase in my app: auth.realm, user.realm etc. So I put all db files into default.realm directory.
You may want to create the folder before opening the realm Something like this
do {
let fileURL = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: "my.app.bundle.id")!
.appendingPathComponent("default.realm")
let realmUrl = fileURL.appendingPathComponent(path)
try fileManager.createDirectory(atPath: fileURL.path, withIntermediateDirectories: true, attributes: nil)
var config = Realm.Configuration(fileURL: realmUrl)
config.schemaVersion = 10
Realm.Configuration.defaultConfiguration = config
let realm = try Realm()
return realm
} catch {
return nil
}
@dianaafanador3 It works well, thanks so much.
How frequently does the bug occur?
All the time
Description
My code is:
This always return nil, I write the error description in
Stacktrace & log output
Stacktrace & log output
Can you reproduce the bug?
Yes, always
Reproduction Steps
No response
Version
10.33.0 and 10.29.0
What SDK flavour are you using?
Local Database only
Are you using encryption?
No, not using encryption
Platform OS and version(s)
MacOS: 13.0.1 (22A400)
Build environment
Xcode version: 14.1 (14B47b) Dependency manager and version: I use Swift Package Manager