编译器错误“使用未声明的标识符”当我删除我的@synthesize语句 [英] Compiler error "use of undeclared identifier" when I remove my @synthesize statements

查看:257
本文介绍了编译器错误“使用未声明的标识符”当我删除我的@synthesize语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用最新的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:


使用未声明的标识符fetchedResultsController,是否意味着_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 。您指的是在删除 @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语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆