RLMString - how to use in array?

release

#1

Hi folks,
Trying to use RLMArray of NSString and not sure how it’s done. Could not find anything in documentation on it. This is latest Realm 3.x something.

Here is our class:

@interface MyClass : RLMObject<NSCopying>
@property RLMArray<RLMString> *listStrings;
@end

Here is what we are trying to do with it, and it errors with:
"caught “RLMException”, "RLMArray does not match expected type ‘string?’ for property ‘MyClass.listStrings’."

MyClass *myClass = [[MyClass alloc] init];
RLMArray<RLMString> *rlmArray = [[RLMArray<RLMString> alloc] initWithObjectClassName:@"NSString"];
[rlmArray [email protected]"First"];
[rlmArray [email protected]"Second"];
myClass.listStrings = rlmArray; <--error here

Can anyone please help with some wonderful advice?
Thanks,

Chris

P.S. Per documentation:
RLMArrays can store primitive values in lieu of Realm objects. In order to do so, constrain a RLMArray with one of the following protocols: RLMBool, RLMInt, RLMFloat, RLMDouble, RLMString, RLMData, or RLMDate.


#2

Anyone out there? (Just bumping the thread up).


#3

The RLMArray initializer you’re using is documented as “for use only in Swift class definitions”. Rather than allocating a new RLMArray and assigning it to your property, mutate the existing instance directly:

MyClass *myClass = [[MyClass alloc] init];
[myClass.listStrings addObject:@"Foo"];