I thought I was doing it correctly.
let realm = try! Realm()
do {
try realm.write {
realm.add(myObject)
}
} catch {
print("something went wrong!")
}
But I'm still getting a crash instead of that print statement. I'm not interested in avoiding the exception (in this case I caused it deliberately by adding an object with an existing primary key) but I want to be able to catch it and prevent a crash no matter what. Is this possible, and if so, how?
Realm Swift throws Objective-C exceptions only for things that are considered to be programmer error. These exceptions are not intended to be caught and handled at runtime as they're indicative of an error in the program that must be fixed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With