覆盖核心数据访问器

时间:2013-09-19 17:22:17

标签: ios objective-c core-data

我正在尝试覆盖我的NSManagedObject访问器:

- (NSSet *)children {

    NSSet *children = nil;

    [self willAccessValueForKey:@"children"];
    children = [self primitiveChildren];
    [self didAccessValueForKey:@"children"];

   //if no children, let's look in our db to see if any children
   //belong to me (parent object), and if they do, let's assign the
   //children to myself (parent)
    if(!children.count) {

         NSFetchRequest *request = [ChildMO fetchRequestForManagedObjectContext:self.managedObjectContext];
         request.predicate = [NSPredicate predicateWithFormat:@"predicate IN %@", @[self.id]];

         children = [NSSet setWithArray:[self.managedObjectContext executeFetchRequest:request error:nil]];

         [self willChangeValueForKey:@"children"];
         [self setPrimitiveChildren:children];
         [self didChangeValueForKey:@"children"];
    }

    return children;
}

但是,当我在将子NSCS分配给我的ManagedObject之前调用'willChangeValueForKey'时,似乎再次调用子getter并进入无限循环状态。

有什么想法吗?

0 个答案:

没有答案