objective-c - 删除 @synthesize 语句时出现编译器错误 "use of undeclared identifier"

标签 objective-c compiler-errors clang synthesize declared-property

在最新的 LLVM 构建中,合成属性的要求已被删除。

因此,我能够删除所有的 @synthesize 语句,NSFetchedResultsController 语句除外。有谁知道为什么当我删除 @synthesize fetchedResultsController; 行时编译器会警告我?

错误:

Use of undeclared identifier "fetchedResultsController", did you mean _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;
}

最佳答案

当您不在代码中放置 @synthesize 时,为支持该属性而创建的实例变量名为 _propertyName。您指的是实例变量 fetchedResultsController,它在您删除 @synthesize 后不再存在。相反,将所有对 fetchedResultsController 的引用更改为 _fetchedResultsController

关于objective-c - 删除 @synthesize 语句时出现编译器错误 "use of undeclared identifier",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14188823/

相关文章:

iphone - 运行我的 iPad 应用程序时黑屏

c++ - 二进制 'operator' : no operator defined which takes a left-hand operand of type 'type' (or there is no acceptable conversion)

linker - 建库时clang和clang++有什么区别?

linux - 使用-O0 编译linux kernel (4.4) bpf samples 导致错误

iphone - 自定义 UITableViewCell 的定位和自定义删除按钮

ios - ScrollView 或 TableView 标题中的 UITable?

ios - 自定义导航栏不更改/显示标题

java - 突然无法在 Intellij 中打开任何 java 程序

java - 尝试在方法内调用方法

c++ - 为什么 clang++ 会对内联的 enable_if 发出警告,然后无法链接?