realm-swift
realm-swift copied to clipboard
Cannot construct `RLMArray<RLMString>` in Swift
I'm not sure if this is a bug or a feature request. It looks like you cannot create an RLMArray of RLMStrings in Swift since Swift requires usage of the RLMArray.init(objectClassName:)
initializer which precludes using the RLMPropertyType.string
property type.
It seems like its sufficient to simply make the following method public in the RLMArray.h
header:
@interface RLMArray (Swift)
// for use only in Swift class definitions
- (instancetype)initWithObjectClassName:(NSString *)objectClassName;
- (instancetype)initWithObjectType:(RLMPropertyType)type optional:(BOOL)optional; // <-- This line is added
@end
Then to construct the array as follows:
@objc public dynamic var myArray = RLMArray<RLMString>(objectType: RLMPropertyType.string, optional: false)
Is this worthwhile to add? Is there any reason why we cannot construct RLMArray
s this way?
Thanks.
Any response on this?
Any response on this?
What is the use case for adding this? Seems like a List<String>
would suit you, but is there an interop case you can post an example of?
@jsflax : I don't recall exactly why I was asking for this, but I'd guess it's to allow usages using KVO.
I was using the ObjC Realm in Swift and faced issue how to declare an array of String
@objc dynamic var paths = RLMArray<RLMString>(objectType: RLMPropertyType.string, optional: false)
turned out
@objc dynamic var paths = RLMArray<RLMString>(objectClassName: String(describing: RLMString.self))