-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
Goals
<!--- What do you want to achieve? -->
Trying to get an object from my Realm database
Expected Results
<!--- What did you expect to happen? -->
Successfully get the required object
Actual Results
<!--- What happened instead?
e.g. the stack trace of a crash
-->
I get a crash with an uncaught exception:
"Inside init: Current thread <NSThread: 0x600000075700>{number = 5, name = (null)}" "Inside getObject: Current thread <NSThread: 0x600000075700>{number = 5, name = (null)}" libc++abi.dylib: terminating with uncaught exception of type NSException
At first I thought it was a threading issue, but you can see that I init the Realm and getObject on the same thread.
Code Sample
<!---
Provide a code sample or test case that highlights the issue.
If relevant, include your model definitions.
For larger code samples, links to external gists/repositories are preferred.
Alternatively share confidentially via mail to help@realm.io.
Full Xcode projects that we can compile ourselves are ideal!
-->
private var database: Realm! init(some_var: String) { var configuration = Realm.Configuration() configuration.fileURL = configuration.fileURL!.deletingLastPathComponent().appendingPathComponent("\(some_var).realm") do { debugPrint("Inside init: Current thread \(Thread.current)") self.database = try Realm(configuration: configuration) } catch { debugPrint("realmInit: Can't create realm database.") } } func getObject<T: Object, K>(with primaryKey: K) -> T? { debugPrint("Inside getObject: Current thread \(Thread.current)") return self.database.object(ofType: T.self, forPrimaryKey: primaryKey) // THIS LINE THROWS EXCEPTION }
Version of Realm and Tooling
<!---
In the CONTRIBUTING guidelines, you will find a script,
which will help determining some of these versions.
-->
Realm framework version: 2.6.2
Realm Object Server version: N/A not using
Xcode version: 8.3.2
iOS/OSX version: OSX 10.12.3
Dependency manager + version: Cocoapods 1.1.1