在对象类型中找不到属性 [英] Property not found in object type
问题描述
我正在开发一个使用tableview和详细视图的简单核心数据应用程序。我收到错误消息,指出在对象类型ChildrenTVC中找不到属性managedObjectContext。问题是它确实存在。我已清理项目并删除了派生数据。必须有其他事情发生。
以下是对象标题的代码:
I am working on a simple core data app that uses a tableview and a detail view. I am getting the error message stating that the property managedObjectContext is not found in the object type ChildrenTVC. The problem is that it really is there. I have cleaned the project and deleted the derived data. There must be something else going on. Here is the code for the object header:
@interface ChildrenTVC : CoreDataTableViewController <AddChildTVCDelegate>
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
@end
以及实施文件的代码:
#import "ChildrenTVC.h"
@implementation ChildrenTVC
@synthesize managedObjectContext = _managedObjectContext;
@synthesize fetchedResultsController = _fetchedResultsController;
这是错误登记的应用程序委托文件:
Here is the app delegate file where the error registers:
#import "AppDelegate.h"
#import "ChildrenTVC.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize managedObjectContext = __managedObjectContext;
@synthesize managedObjectModel = __managedObjectModel;
@synthesize persistentStoreCoordinator = __persistentStoreCoordinator;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: ( NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
ChildrenTVC *controller = (ChildrenTVC *)navigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
return YES;
}
错误发生在controller.managedObjectContext。很多这是样板代码所以没有多少。我只是无法弄清楚为什么它没有看到托管对象上下文的属性。该属性在代码中。
The error is at the controller.managedObjectContext. A lot of this is boilerplate code so there is not much to it. I just can't figure out why it is not seeing the property for the managed object context. The property is in the code.
UPdate:
我最终完全重新创建了该文件。我不确定更改文件时仍有哪些引用,但有些内容指向错误的文件。我不得不清空垃圾桶以使新文件正常工作。但它现在似乎工作了。我所做的所有研究最终都揭示了Xcode中存在一些无法解释的事情。
I ended up recreating the file entirely. I am not sure what references are still in place when a file is changed, but something was pointing to the wrong file. I had to empty the trash to get the new file work properly. It seems to work now, though. All the research I did ended up revealing that there are some things that are unexplained in Xcode.
推荐答案
我通过以下方式解决了这个问题完全重新创建头文件,但我从来没有真正理解为什么会发生这种情况。那时我不明白的是我对应用程序所做的更改的影响。真正的问题是导入头文件的顺序问题。我在两个实现文件中更改了#import,导致编译器无法读取其中一个头文件。我可以看到代码在那里,但编译器无法读取代码,因为它没有导入它。这让位给我收到的错误。我的解决方案只是扭转了我所做的改变。只需删除应用程序委托上的视图控制器头文件的#import,就可以更轻松地解决这个问题。我最近测试了这个,这是正确的解决方案。
I had solved this issue by entirely recreating the header file, but I never really understood why it happened. What I did not understand then were the effects of the changes that I had made to the app. The real problem was an issue in the sequence that the header files were imported. I had changed the #import in two implementation files and that caused the compiler to not read one of the header files. I could see that the code was there, but the compiler could not read the code because it was not importing it. That gave way to the error I was receiving. My solution simply reversed the change that I had made. It would more easily have been solved by simply removing the #import of the view controller header file on the app delegate. I recently tested this and it was the correct solution.
这篇关于在对象类型中找不到属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!