RLMObject with Array of NSStrings

匿名 (未验证) 提交于 2019-12-03 02:24:01

问题:

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:

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 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!