我有2個自動生成的實體:得到的NSSet相關/相關實體 - CoreData
@interface ContactEntity : Entity
@property (nonatomic, retain) NSString *caption;
@property (nonatomic, retain) NSString *image;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *text;
@property (nonatomic, retain) NSSet *pointLink;
@end
@interface PointEntity : Entity
@property (nonatomic, retain) NSNumber *latitude;
@property (nonatomic, retain) NSNumber *longitude;
@property (nonatomic, retain) NSSet *entityLink;
@property (nonatomic, retain) EntityEntity *entityTypeLink;
@end
它們之間相互聯繫的多對多,即一個接觸有很多點,一個點有內多次接觸。
然後,我得到第一個實體:
ContactModel *contact = [[[ContactModel alloc] init] autorelease];
// this is FetchRequest, returns array of all entities
self.items = [contact list:contact];
// i get only one, all is OK here, this entity has related PointEntity in DB
ContactEntity *contactEntity = [self.items objectAtIndex:self.selection];
,當我嘗試在選擇ContactEntity使用NSSet中獲得相關PointEntity我總是得到空或空數組。這兩個作品都沒有:
NSArray *points = [contactEntity.pointLink allObjects];
PointEntity *pointEntity = [contactEntity.pointLink anyObject];
NSInteger x1 = [points count]; // always 0
id x2 = pointEntity.latitude; // always 0
for (PointEntity *x in contactEntity.pointLink) // isn't enumerated because count = 0
{
id x3 = x.latitude;
}
任何想法表示讚賞。我錯過了什麼,也許我需要使用NSPredicate從PointEntity中選擇與ContactEntity相關的實體?
謝謝。
P.S.我的問題是類似的,但這個建議不適用於我,我不能使用主要實體的NSSet加載關聯實體:( CoreData: many-to-many relationship