NSManagedObjectClass中的函数失败

时间:2013-05-13 13:19:48

标签: iphone ios objective-c core-data nsmanagedobject

我有一个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)

崩溃

任何帮助?

0 个答案:

没有答案