代码之家  ›  专栏  ›  技术社区  ›  BarrettJ

核心数据问题-EXC\u访问错误

  •  0
  • BarrettJ  · 技术社区  · 16 年前

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"TVShow" inManagedObjectContext:[self managedObjectContext]];
    [fetchRequest setEntity:entity];
    
    [fetchRequest includesPendingChanges];
    //NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ID == %@", showId];
    //[fetchRequest setPredicate:predicate];
    
    NSError *error;
    
    NSLog(@"Generating Count");
    
    NSUInteger count = [[self managedObjectContext] countForFetchRequest:fetchRequest error:&error];
    
    if(count == NSNotFound) {
        NSLog(@"error");
    }
    else {
        NSLog(@"%@", count); // EXC_BAD_ACCESS here
    }
    
    [fetchRequest release];
    
    1 回复  |  直到 16 年前
        1
  •  4
  •   user121301 user121301    16 年前

    在整数的格式字符串中使用%d而不是%@

    NSLog(@"%d", count);
    

    这是一份 String Format Specifiers