将字符串类型数组存储在RealM目标c中

将字符串类型数组存储在RealM目标c中

本文介绍了将字符串类型数组存储在RealM目标c中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数组的字符串类型存储在领域目标c 中.

i want to store string type of array in Realm objective c.

Ex数组:-的 [ 58575bc922e87bd14480132f", 58575c5c22e87bd144801331", 58575cc922e87bd144801333", 58575d5b22e87bd144801335", 58575bc922e87bd14480132f", 58575c5c22e87bd144801331", 58575cc922e87bd144801333", 58575d5b22e87bd144801335", 58575bc922e87bd14480132f", 58575c5c22e87bd144801331", 58575cc922e87bd144801333",58575d5b22e87bd144801335 ]

推荐答案

您可以从RLMObject类继承,并将NSString作为属性放入您的RLMObject中.然后,您可以再次使用以前制作的RLMObject的RLMArray来制作新的RLMObject.

You can inherit from RLMObject class and put the NSString into your RLMObject as a property.Then you can make new RLMObject one more time, with a RLMArray of previously made RLMObject now.

@interface StringObject: RLMObject
@property NSString *stringValue;
@end

@interface RealmObject: RLMObject
@property RLMArray<StringObject> *realmArray
@end

进行此操作后,可以随时使用它. F.e.使用快速枚举循环将字符串放入RLMArray领域.

After this manipulation feel free to use it. F.e. use fast enumeration loop to put the strings into realm RLMArray.

NSArray *arrayOfStrings = @[@"58575bc922e87bd14480132f",@"58575c5c22e87bd144801331",@"58575cc922e87bd144801333",@"58575d5b22e87bd144801335",@"58575bc922e87bd14480132f",@"58575c5c22e87bd144801331",@"58575cc922e87bd144801333",@"58575d5b22e87bd144801335",@"58575bc922e87bd14480132f",@"58575c5c22e87bd144801331",@"58575cc922e87bd144801333",@"58575d5b22e87bd144801335"];

RLMRealm *realm = [RLMRealm defaultRealm];

RealmObject *realmObject = [RealmObject new];
for (NSString *value in arrayOfStrings) {
    StringObject *string = [StringObject new];
    string.stringValue = value;

    [realmObject.realmArray addObject:string];
}

[realm beginWriteTransaction];
[realm addObject:realmObject];
[realm commitWriteTransaction];

感谢带有NSString数组的RLMObject
https://github.com/realm/realm-cocoa/issues/3415

Thanks to RLMObject with Array of NSStrings
Andhttps://github.com/realm/realm-cocoa/issues/3415

这篇关于将字符串类型数组存储在RealM目标c中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 13:47