Reputation: 8165
Right now I'm in the process of migrating from Swift 1.2 to Swift 2.0.
The project I'm working on uses Realm as a database. Everything works fine in Swift 1.2 on both, device and simulator. But I get this error with Swift 2.0 when running app on device:
fatal error: 'try!' expression unexpectedly raised an error: Error
Domain=io.realm Code=1 "open() failed: Operation not permitted"
UserInfo=0x145e2bc0 {Error Code=1, NSLocalizedDescription=open() failed:
Operation not permitted}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-
700.0.57.3/src/swift/stdlib/public/core/ErrorType.swift, line 50
Realm is being initialized with this base path:
NSSearchPathForDirectoriesInDomains(.DocumentDirectory,
.UserDomainMask, true).first!
i.e. user documents directory. I can access files with NSFileManager and actually see Realm files there.
Any clues how to debug this issue? Seems that Realm just crashes on initialization.
Upvotes: 3
Views: 2359
Reputation: 15991
If you're getting an open() failed
error, more often than not, it means that the path you've supplied is still invalid in some way.
In this case, I'm guessing you might not have specified the actual file name of the Realm file you wish to create in that Documents path. When setting the path of a Realm file (Whether the default one, or a new one), you have to make sure the path is an absolute one, down to and including the file name.
Upvotes: 2