realm-swift: Realm fails to access property on RealmSwiftObject instance
Goals
I am fetching custom objects from a REST service. A framework of mine transforms the JSON into Realm instances. The model class is the following:
public class ObservingSite: Object {
public dynamic var uuid: String = ""
public dynamic var name: String = ""
override public static func primaryKey() -> String? {
return "uuid"
}
}
These instances are saved into a realm, and then transferred into the app using the custom framework. However, at that time, I just can’t access the properties name or uuid. On the other hand the po command in the debugger shows the correct properties values!
Somehow, I don’t have this problem at all when fetching single objects. As far as I can tell, this is similar (or related to) #4005 maybe?
Expected Results
I expect to be able to access the values of these properties.
Actual Results
The runtime result of this is:
-[RealmSwiftObject name]: unrecognized selector sent to instance 0x61000008d8e0
When I set a breakpoint just before accessing the property in my app code, and use the po command, I get the following (the instance is site):
(lldb) po site
ObservingSite {
uuid = 99b98d50-d831-48c2-89b3-2ff6e4c9f4aa;
name = Adelaide Observatory;
}
(lldb) po site.name
2017-01-28 10:48:56.220043 iObserve2[16158:347963] -[RealmSwiftObject name]: unrecognized selector sent to instance 0x608000089060
error: Execution was interrupted, reason: internal ObjC exception breakpoint(-3)..
The process has been returned to the state before expression evaluation.
Steps to Reproduce
I tried the above code in 2 apps and I get the same thing. The custom framework I use is available here: https://github.com/onekiloparsec/arcsecond.swift
Code Sample
And the code to fetch the observing sites is like this:
_ = ArcsecondService.sharedDefault.observingSites(closure: { (sites, event) in
if let obsSites = sites {
Swift.print("\(obsSites)")
if let site = obsSites.first {
Swift.print("\(site.name)")
}
}
})
Version of Realm and Tooling
Realm version: 2.4.1
Xcode version: 8.2.1
iOS/OSX version: 10.12.3
Dependency manager + version: Carthage (latest)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 23 (9 by maintainers)
I can verify that a clean after step 4 fixes the issue. I upgraded realm to the latest version in my application, did a clean build and it is working fine 👍
I have been able to reproduce the issue in the following project.
Steps to reproduce
v2.3.0Crash or notbutton to verify that you can access the added objectsv2.4.1Crash or notbutton.