2
votes

When I call:

[RLMRealm realmWithPath:@"example.realm"]

It crashes and logs:

Terminating app due to uncaught exception 'RLMException', reason: 'open() failed: Operation not permitted'

How do I create a specific realm file besides using default.realm and [RLMRealm defaultRealm]? Am I missing something from the documentation?

2
Hi Tim from Realm here. Sorry about that! I don’t think we’ve seen this bug reported yet. I need a bit more details: Are you crashing on a device or in the simulator? Do you have disk space still available? - timanglade
Hi Tim, thanks for helping me! I am testing this on my device, iPhone 6. I have disk space available. I have tried to call [RLMRealm realmWithPath:@"example.realm"] in my example app but it would crash the app. I assumed that the error meant that I had to first create the example.realm file in order to write to it but I thought realmWithPath would automatically do that for you. - kevinnguy
I am using 0.85.0 and getting the framework via CocoaPods - kevinnguy
It breaks in group_shared.hpp #ifdef TIGHTDB_ENABLE_REPLICATION inline SharedGroup::SharedGroup(Replication& repl): m_group(Group::shared_tag()), m_transactions_are_pinned(false) { open(repl); } #endif - kevinnguy

2 Answers

7
votes

You are right that this is the way to create a new realm file, and if you provide a full path to a writable location in the file system, it will work:

NSString *documentsDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *customRealmPath = [documentsDirectory stringByAppendingPathComponent:@"example.realm"];
RLMRealm *realm = [RLMRealm realmWithPath:customRealmPath];

EDIT: Updated to a path that works on devices as well as the simulator

0
votes

See my answer https://github.com/realm/realm-cocoa/issues/4221

If you use realm file in bundle, it will crash in the device. Need to specify readonly

readOnly: Whether the Realm is read-only (must be true for read-only files).

let path = Bundle.main.url(forResource: "mydata", withExtension: "realm")!
let configuration = Realm.Configuration(fileURL: path, readOnly: true)
realm = try! Realm(configuration: configuration)