Compiler error “use of undeclared identifier” when I remove my @synthesize statements

空扰寡人 提交于 2019-12-12 13:01:02

问题


With the latest LLVM build, the requirement for synthesizing properties has been removed.

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?

Error:

Use of undeclared identifier "fetchedResultsController", did you mean _fetchedResultsController?

This is my code:

@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;
}

回答1:


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.




回答2:


Because the default synthesized variable is _fetchedResultsController not fetchedResultsController




回答3:


The property fetchedResultsController is automatically synthesized to _fetchedResultsController, and this happens for every synthesized variable.

You should synthesize it explicitly to change its name.



来源:https://stackoverflow.com/questions/14188823/compiler-error-use-of-undeclared-identifier-when-i-remove-my-synthesize-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!