我有一个NSManagedObjectClass
收藏夹。在这个类中,我有一个方法getFavoritesByArtistId
你可以在这里看到它。
-(Favorites *)getFavoriteById:(int)art_id{
Favorites *favorite;
NSLog(@"artist is is %d",art_id);
RKManagedObjectStore *store = [[GenkonStageDataModel sharedDataModel] objectStore];
NSManagedObjectContext *context = store.mainQueueManagedObjectContext;
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Favorites"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"fav_art_id == %d",art_id];
[fetchRequest setPredicate:predicate];
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"fav_id" ascending:YES];
fetchRequest.sortDescriptors = @[descriptor];
NSArray *matches = [context executeFetchRequest:fetchRequest error:nil];
if (matches.count > 0){
NSLog(@"till here");
favorite = [matches objectAtIndex:0];
}else {
NSLog(@"till here 2");
return NULL;
}
return favorite;
}
在我的视图控制器中,我这样称呼它。
RKManagedObjectStore *store = [[GenkonStageDataModel sharedDataModel] objectStore];
NSManagedObjectContext *context = store.mainQueueManagedObjectContext;
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Favorites" inManagedObjectContext:context];
Favorites* favClass = [[Favorites alloc] initWithEntity:entityDescription insertIntoManagedObjectContext:context];
Favorites *favorite = [favClass getFavoriteById:[artist.art_id intValue]];
接下来我要检查
if(![favorite isKindOfClass:[NSNull class]]){
//Artist is already favorized !
}else{
//Artist is not favorized !
}
但是我的应用程序总是因此崩溃CoreData _PFFastEntityRangesByType + 12, stop reason = EXC_BAD_ACCESS (code=1, address=0x38)
有什么帮助吗?