这是我的核心数据GeneratedCode,由xCode编辑器自动生成。
#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假设我想“清除”所有评论和图片。
做self.Reviews=nil能解决这个问题吗?
我知道做self.LatitudeLongitude=nil会删除self和它的LatitutudeLongitude之间的关系。
发布于 2011-05-13 11:52:32
编辑-不确定你的意思是不是像delete中那样是“清除”。下面我的回答是假设您希望对象从上下文中移除;而不仅仅是切断NSManagedObjects
我不相信
self.Reviews = nil;将实际删除托管对象上下文的审阅对象。这将向每个对象发送释放消息,但是要从您必须调用的上下文中删除它们
` `aContext :reviewObj;`
在集合中的每一个上。如果您要删除一个业务对象(使用如上所示的"deleteObject“),并且您将关系删除规则设置为"Cascade",那么我相信这将导致所有的评论、城市等……自动删除该业务对象所拥有的对象,但据我所知,这是导致NSManagedObjects被删除的唯一其他方法。
https://stackoverflow.com/questions/5986728
复制相似问题