3

在最新的 LLVM 版本中,已删除对综合属性的要求。

因此,我能够删除我@synthesize的所有陈述,除了NSFetchedResultsController. 有谁知道为什么当我删除该@synthesize fetchedResultsController;行时编译器会警告我?

错误:

使用未声明的标识符“fetchedResultsController”,您的意思是 _fetchedResultsController 吗?

这是我的代码:

@property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController;

@synthesize fetchedResultsController;

- (NSFetchedResultsController *)fetchedResultsController {
    if (fetchedResultsController) {
        return fetchedResultsController;
    }

    if (!self.managedObjectContext) {
        self.managedObjectContext = [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
    }

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Session" inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:entity];

    [fetchRequest setPredicate: self.predicate];

    [fetchRequest setFetchBatchSize:20];

    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timeStamp" ascending:NO];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];

    [fetchRequest setSortDescriptors:sortDescriptors];

    fetchedResultsController= [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
    fetchedResultsController.delegate = self;

    NSError *error = nil;
    if (![fetchedResultsController performFetch:&error]) {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }

    return fetchedResultsController;
}
4

3 回答 3

4

如果您没有@synthesize在代码中添加 ,则为支持该属性而创建的实例变量名为_propertyName。您指的是fetchedResultsController删除后不再存在的实例变量@synthesize。相反,将所有引用更改fetchedResultsController_fetchedResultsController

于 2013-01-07T01:52:25.560 回答
1

因为默认的合成变量_fetchedResultsController不是fetchedResultsController

于 2013-01-07T01:52:57.893 回答
1

该属性fetchedResultsController会自动合成为_fetchedResultsController,并且对于每个合成变量都会发生这种情况。

您应该显式合成它以更改其名称。

于 2013-01-07T01:53:12.533 回答