嗨我想能夠撕毀核心數據中的一些信息,但我不確定如何檢查文件是否正確保存。我嘗試使用NSLog,但它調用時返回null。我有一個字典,它有一個uniqueID和一個我想要保存的標題。我將其與數據庫的上下文一起傳遞。然後我排序數據庫來檢查它是否有任何重複,如果沒有,那麼我添加文件。如何檢查是否存儲在CoreData
+(VacationPhoto*) photoWithFlickrInfo: (NSDictionary*) flickrInfo inManagedObjectContext: (NSManagedObjectContext*) context{
//returns the dictionary
NSLog(@"Photo To Store =%@", flickrInfo);
VacationPhoto * photo = nil;
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"VacationPhoto"];
request.predicate = [NSPredicate predicateWithFormat:@"uniqueID = %@", [flickrInfo objectForKey:FLICKR_PHOTO_ID]];
NSSortDescriptor * descriptor = [NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES];
request.sortDescriptors = [NSArray arrayWithObject:descriptor];
NSError *error = nil;
NSArray *matches = [context executeFetchRequest:request error:&error];
if (!matches || [matches count] > 1) {
// handle error
} else if ([matches count] == 0){
photo.title = [flickrInfo objectForKey:FLICKR_PHOTO_TITLE];
//Returns NULL when called
NSLog(@"title = %@", photo.title);
photo.uniqueID = [flickrInfo objectForKey:FLICKR_PHOTO_ID];
//Returns NULL when called
NSLog(@"ID = %@", photo.uniqueID);
} else {
//If photo already exists this is called
photo = [matches lastObject];
}
return photo;
}
我不認爲文件被正確保存,因爲我試圖調用該方法兩次使用相同的信息,而不是說一個副本的第二期間已發現迭代它,而不是進入if語句,當沒有這樣的文件 –