使用最新的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;
}
答案 0 :(得分:4)
如果未在代码中放置@synthesize
,则为备份属性而创建的实例变量名为_propertyName
。您指的是删除fetchedResultsController
后不再存在的实例变量@synthesize
。相反,请将对fetchedResultsController
的所有引用更改为_fetchedResultsController
。
答案 1 :(得分:1)
因为默认的合成变量是_fetchedResultsController
而不是fetchedResultsController
答案 2 :(得分:1)
属性fetchedResultsController
自动合成到_fetchedResultsController
,每个合成变量都会发生这种情况。
您应该明确地合成它以更改其名称。