问题描述
使用最新的LLVM版本,合成属性的要求已删除。
With the latest LLVM build, the requirement for synthesizing properties has been removed.
因此,我能够删除所有的 @synthesize
语句,除了 NSFetchedResultsController
的语句。有没有人知道为什么当我删除 @synthesize fetchedResultsController;
行时,编译器警告我?
Therefore I was able to remove all my @synthesize
statements except for the ones for NSFetchedResultsController
. Does anyone know why the compiler is warning me when I remove the @synthesize fetchedResultsController;
line?
错误: / p>
Error:
这是我的代码:
@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
。您指的是在删除 @synthesize
后不再存在的实例变量 fetchedResultsController
。请改为将 feticedResultsController
的所有引用更改为 _fetchedResultsController
。
When you don't put an @synthesize
in your code, the instance variable created to back the property is named _propertyName
. You are referring to the instance variable fetchedResultsController
which no longer exists after you remove the @synthesize
. Instead, change all references to fetchedResultsController
to _fetchedResultsController
.
这篇关于编译器错误“使用未声明的标识符”当我删除我的@synthesize语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!