11

I've been upgrading a project to use Realm as the persistence store and I'm not able to find any documentation on how to use an array of strings in one of my models.

The implementation of an Array for a RLMObject is to use an RLMArray where T inherits RLMObject

I could make an object that inherits.. property inside which is string... but that seems like quite some overhead to replace an NSArray of strings.

Does anyone know the recommended best practice to do this?

1 Answer 1

23

As of Realm Cocoa 3.0 you can simply do RLMArray<RLMString> *array; and no longer need the wrapper object type.


In older versions of Realm you need an RLMObject which contains the string:

@interface StringObject : RLMObject
@property NSString *value;
@end
RLM_ARRAY_TYPE(StringObject)

@implementation StringObject
@end

@interface Object : RLMObject
@property RLMArray<StringObject> *array;
@end
Sign up to request clarification or add additional context in comments.

3 Comments

Am I the only one with this error? this class is not key value coding-compliant for the key value.
@Thomas Goyne, Converting StringObject back to NSSString (i.e. stringObj.value) gives error. Any idea ?
didnt work for me, StringObject and NSString does work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.