使用最新的LLVM版本,不再需要合成属性。
因此,我能够删除除@synthesize
之外的所有NSFetchedResultsController
语句。有谁知道为什么我删除@synthesize 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
。