2011-05-13 171 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被刪除。