Closed SandyChapman closed 8 years ago
Realm Swift has never been tested on iOS 7 specifically due to that it's designed with the assumption that it'll be used as a Swift module, and we strongly recommend that you use the Objective-C API with RLMSupport.swift
if you need to target iOS 7.
requiredProperties
doesn't exist in the RealmSwift version of Object because in Swift you can just directly declare properties as optional or not optional, while in obj-c there's no (reasonable) way to put that into the property definition. However, your subclasses are being treated as obj-c classes because there's several places in the obj-c code where we look up classes defined in the Swift code by their fully-qualified names, and this is failing because your app is presumably not named RealmSwift. At the minimum you'll need to replace all of the occurrences of "RealmSwift" in the source for Realm.framework with the name of the target that the Swift code is being compiled in to.
The +requiredProperties
message is only intended to be sent to Objective-C classes. The fact it's being sent to a Swift class suggests that either we're incorrectly detecting the language of the class (see the first few lines of +[RLMObjectSchema schemaForObjectClass:]
), or that RealmSwift isn't loaded (leading to RLMObjectUtilClass
returning RLMObjectUtil
rather than RealmSwift.ObjectUtil
). Given your comment about the non-standard way you're building RealmSwift, I suspect it's the latter.
@tgoyne @bdash : Thanks for the tips. Since I've already invested a bit in using the Swift version of the API, I'll see if I can adapt it to my project's target. If not, I'll have to fall back onto using the ObjC API. I'll follow up shortly on my progress with details in case anyone else is looking to do something similar.
Since you're using Realm in a way we explicitly don't support, I'll close this issue. However, please do share what you end up doing, I'm sure we're all curious to see!
@jpsim @tgoyne @bdash : So I have this working. I have yet to run the unit tests, but the changes to support using RealmSwift in any Swift module is pretty simple. A total of 5 lines changed. This also shouldn't break support in the existing RealmSwift module. Are you guys interested in me contributing this? Since it's not explicitly supported I'd understand if you didn't want a PR, but if you do, I can go through the PR process (figured I'd ask before wasting time on it)
@jpsim @tgoyne @bdash
See my diff here: https://github.com/lixar/realm-cocoa/commit/20cf23548afba2ccd618c9a26d8a9ed5a3714759
Let me know if you want a PR and on which branch you'd like it on (you guys have a lot of them).
I'm attempting to include the RealmSwift source files directly into my app and using a the Realm static framework. The reason being that I want to utilize RealmSwift while retaining support for targeting iOS 7. I've gotten this to compile, however, I'm hitting an issue when I attempt to do anything using Realm at runtime.
I'm getting the following error:
This happens even not utilizing the Swift Realm classes and use the Objective-C classes instead. If I add the following line to the
RealmSwift.Object
class, the code will execute and the error is avoided:Is there any danger in doing this to get around the crash? Am I missing anything? What typically provides the definition for this
requiredProperties
call that I'm overlooking? If I'm looking to implement this method myself in my classes, what should be returned?Thanks.