Ios commitWriteTransaction上的Realm.io rlmeException-索引超出范围

Ios commitWriteTransaction上的Realm.io rlmeException-索引超出范围,ios,realm,Ios,Realm,我已经成功地使用了以下代码,突然,对于我的一个模型,Realm在commitWriteTransaction上抛出了一个索引越界错误。领域对象被成功创建,并且只有在下面的最后一行出现错误,并且只发生在我的一个模型上。我最近确实更新了服务器返回,但是模型仍然正确,因为它成功地从服务器数据创建了一个对象(模型如下所示) 顺便说一句,每次应用程序崩溃时,我都需要删除并重新安装它。如果我再次尝试打开它,它将在到达任何地方之前崩溃(我假设这是因为数据库混乱) 发生什么事了?我该如何解决这个问题 代码: N

我已经成功地使用了以下代码,突然,对于我的一个模型,Realm在
commitWriteTransaction
上抛出了一个索引越界错误。领域对象被成功创建,并且只有在下面的最后一行出现错误,并且只发生在我的一个模型上。我最近确实更新了服务器返回,但是模型仍然正确,因为它成功地从服务器数据创建了一个对象(模型如下所示)

顺便说一句,每次应用程序崩溃时,我都需要删除并重新安装它。如果我再次尝试打开它,它将在到达任何地方之前崩溃(我假设这是因为数据库混乱)

发生什么事了?我该如何解决这个问题

代码:

NSDictionary *responseDictionary = (NSDictionary *)responseObject; //response from AFNetworking call to my server
RLMRealm *realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
for (NSDictionary *dict in responseDictionary){
    MyModel *object = [[class alloc] initMyModelWithDictionary:dict]; //class is known
    // (print object) - see output below
    [realm addOrUpdateObject:object];
}
[realm commitWriteTransaction]; // Error thrown here
Terminating app due to uncaught exception 'RLMException', 
reason: 'Index 0 is out of bounds (must be less than 0)'
模型打印输出示例(来自
dict
的示例之一)

错误:

NSDictionary *responseDictionary = (NSDictionary *)responseObject; //response from AFNetworking call to my server
RLMRealm *realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
for (NSDictionary *dict in responseDictionary){
    MyModel *object = [[class alloc] initMyModelWithDictionary:dict]; //class is known
    // (print object) - see output below
    [realm addOrUpdateObject:object];
}
[realm commitWriteTransaction]; // Error thrown here
Terminating app due to uncaught exception 'RLMException', 
reason: 'Index 0 is out of bounds (must be less than 0)'

只有当
RLMArray
RLMLinkingObjects
RLMResults
具有越界访问权限时,才会引发此异常。如果索引0超出范围,则在访问第0个索引时,该索引必须为空。当您调用
commitWriteTransaction
时,Realm本身没有访问此集合。相反,它向执行越界访问的代码发送通知。通过打开异常断点,您应该能够轻松地找到发生这种情况的位置