嗨,我希望能够撕毁核心数据中的一些信息,但我不确定如何检查文件是否正确保存。我尝试使用 NSLog 但它在调用时返回 null 。我有一本字典,它有一个 uniqueID 和一个我想保存的标题。我将它与数据库的上下文一起传递。然后我对数据库进行排序以检查它是否有任何重复项,如果没有,则添加文件。
+(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;
}