2011-05-13 137 views
0

这是我的核心数据的GeneratedCode,由xCode Editor自动生成。核心数据中的许多关系

#import <Foundation/Foundation.h> 
#import <CoreData/CoreData.h> 

@class Building, Category, City, District, Image, LatitudeLongitude, OpeningHour, Promotion, Rating, Review, URL; 

@interface Business : NSManagedObject { 
@private 
} 
@property (nonatomic, retain) NSString * Website; 
@property (nonatomic, retain) NSString * Email; 
@property (nonatomic, retain) NSString * Street; 
@property (nonatomic, retain) NSString * InBuildingAddress; 
@property (nonatomic, retain) NSString * Phone; 
@property (nonatomic, retain) NSString * Title; 
@property (nonatomic, retain) NSString * Zip; 
@property (nonatomic, retain) NSNumber * Price; 
@property (nonatomic, retain) NSSet* Promotions; 
@property (nonatomic, retain) Building * Building; 
@property (nonatomic, retain) NSSet* Categories; 
@property (nonatomic, retain) LatitudeLongitude * LatitudeLongitude; 
@property (nonatomic, retain) NSSet* Images; 
@property (nonatomic, retain) OpeningHour * OpeningHour; 
@property (nonatomic, retain) NSSet* Reviews; 
@property (nonatomic, retain) NSSet* URLs; 
@property (nonatomic, retain) Rating * Rating; 
@property (nonatomic, retain) NSSet* Districts; 
@property (nonatomic, retain) City * City; 

//我加了这3行,为什么不自动生成代码的一部分?

- (void)addDistrictsObject:(District *)value; 
- (void)addCategoriesObject:(Category *)value; 
- (void)addReviewsObject:(Review *)value; 

@end 

说我想“清除”所有评论和图像。

Will doing self.Reviews = nil do the trick?

我知道做self.LitudeitudeLongitude = nil会删除自己和它的LatitutudeLongitude之间的关系。

回答

1

编辑 - 不确定你的意思是“清除”,如删除。我在下面的回答是假设你想让对象从上下文中消失;不只是切断NSManagedObjects

之间的关系,我不相信

self.Reviews = nil; 

居然会删除您的评论的对象为管理对象上下文。这将发送释放消息中的每一个,但是从你的情况下删除它们调用

[aContext deleteObject:reviewObj];

每个组中的一个。如果您要删除其中一个Business对象(使用上面显示的“deleteObject”),并且将关系删除规则设置为“Cascade”,那么我相信这会导致所有Review,City等...对象由该Business对象拥有,并被自动删除,但这是我唯一知道的其他方式会导致NSManagedObjects被删除。