我有一个名为CollectedLeaf的核心数据实体。
@interface CollectedLeaf : NSManagedObject <LeafletRecognitionRequestDelegate>
{
id <CollectedLeafDelegate> delegate_;
}
@property (nonatomic, assign) id <CollectedLeafDelegate> delegate;
@property (nonatomic, retain) NSString* leafID;
@property (nonatomic, retain) NSString* selectedSpecies;
@property (nonatomic, retain) NSString* latitude;
@property (nonatomic, retain) NSString* longitude;
@property (nonatomic, retain) NSString* altitude;
@property (nonatomic, retain) NSDate* collectedDate;
@property (nonatomic, retain) NSData * localImage;
@property (nonatomic, retain) LeafletURL* originalImageURL;
@property (nonatomic, retain) LeafletURL* segmentedImageURL;
@property (nonatomic, retain) Species* selectedSpeciesRel;
@property (nonatomic, retain) NSNumber* syncStatus;
@property (nonatomic, retain) NSDate* lastModified;
@property (nonatomic, retain) NSNumber* uploaded;
@property (nonatomic, retain) NSString* userDataset;
@property (nonatomic, retain) NSSet* CandidateSpecies;
如果没有互联网连接,我会将UIImagePickerController
拍摄的图像转换为NSData
并存储到我的核心数据中。
if (_internetReachability == NotReachable){
//Internet Connection Not Available
if(imageToUpload){
//They just tried to upload photo
self.originalImageView.image = [UIImage imageWithData:imageToUpload];
/*Save photo to core data here*/
NSManagedObjectContext* context = self.collectedLeaf.managedObjectContext;
collectedLeaf.localImage = imageToUpload;
NSError* error;
[context save:&error];
}
只要有互联网连接,我就会将图像上传到服务器。但我知道在本地保存图像会占用大量内存,所以我想删除本地图像(只是分配给属性的值,而不是整个对象)。我可以用collectedLeaf.localImage = nil
删除图像吗?
答案 0 :(得分:0)
您可以将localImage
设置为nil
来删除图像。
// Upload the image to server
collectedLeaf.localImage = nil;
NSError* error;
[context save:&error];