我只想创建一个DEFAULT RMRealm,但仍然崩溃

时间:2016-02-08 13:07:08

标签: ios objective-c realm

 Terminating app due to uncaught exception 'RLMException', reason: ''NSMutableArray' is not supported as an RLMObject property. All properties must be primitives, NSString, NSDate, NSData, RLMArray, or subclasses of RLMObject.

请帮忙。我不知道如何将它包含在RLMArray中

NSDictionary *res = [NSJSONSerialization JSONObjectWithData:self.responseData options:NSJSONReadingMutableLeaves error:&myError];
 //  NSLog(@"%@",res);

for (NSDictionary *collectionDict in [res objectForKey:@"pois"])
{
    RLMRealm *defaultREALM=[RLMRealm defaultRealm];
    [defaultREALM beginWriteTransaction];
    NSMutableDictionary *mCollectionDict = [collectionDict mutableCopy];
    mCollectionDict[@"Firstname"] = collectionDict[@"name"];
    [mCollectionDict removeObjectForKey:@"name"];
    NSLog(@"%@===>%@",collectionDict,collectionDict[@"name"]);
    [defaultREALM commitWriteTransaction];
}

1 个答案:

答案 0 :(得分:1)

从我在示例中收集的内容中,您尝试序列化JSON流然后将其传递给Realm。不幸的是,那里的NSArray是Realm无法接受的地方。

通常,您需要手动处理字典的内容,以确保其中的每个值都与您的Realm模型兼容。幸运的是,有一个可以为您处理的第三方库。我绝对建议您查看Realm-JSON这种情况。 :)