开发者

After adding objects via CoreDataGeneratedAccessors to-many relationships's NSSet is empty

I have two Core Data entities: Parent and Child. Parent has to-many relationship to a Child called children. Inverse relationship from is Child.parent. So parent has CoreDataGeneratedAccessors: - (void)addChildrenObject:(Child *)value; and - (void)addChildren:(NSSet *)value;.

Problem: after I add Child(s) by using one of those accessors and save managedObjectContext parent.children is empty. At the same time parent property of every added Child point to proper instance of Parent and NSFetchedResultsController fetches such children (predicate is parent = %@, <instance of Parent>) well.

How can it be so? Just don't have a clue how to debug such a开发者_JAVA技巧 strange CoreData behavior.


Solved. Somehow property of that set was sythesized by @synthesize not @dynamic in .m file. I know this was a very stupid typo, but I wonder why XCode did not even generated a warning about that! Static analyzer said nothing about it too!


The same happens when you define properties like this:

@interface Project : BaseModel {
  Workspace *workspace;
  NSString *name;
}

@property (nonatomic, retain) Workspace *workspace;
@property (nonatomic, retain) NSString *name;

Correct interface should look like this:

@interface Project : BaseModel {}

@property (nonatomic, retain) Workspace *workspace;
@property (nonatomic, retain) NSString *name;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜