[英]Receiver type is forward declaration
I have this code (along with other stuff): 我有这个代码(以及其他东西):
- (NSManagedObjectContext *) managedObjectContext
{
assert([NSThread isMainThread]);
if (_managedObjectContext != nil) {
return _managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
_managedObjectContext = [[NSManagedObjectContext alloc] init];
[_managedObjectContext setPersistentStoreCoordinator: coordinator];
}
return _managedObjectContext;
}
These lines are giving me errors that class message is a forward declaration: 这些行给了我错误,类消息是一个前向声明:
_managedObjectContext = [[NSManagedObjectContext alloc] init];
[_managedObjectContext setPersistentStoreCoordinator: coordinator];
What is this and how do I fix it? 这是什么,我该如何解决?
You must import CoreData/CoreData.h in the file Supporting Files/YourApp-Prefix.pch: 您必须在Supporting Files / YourApp-Prefix.pch文件中导入CoreData / CoreData.h:
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#endif
By forward Declaration means you must be declaring class by @Class
. 通过前向声明意味着您必须通过
@Class
声明类。 Import the Class in the .h/.m file and hope so it will resolve the issue. 导入.h / .m文件中的类,希望它能解决问题。
将其添加到.h或.m文件的顶部
#import <CoreData/CoreData.h>
我通过在使用Swift类的Objective C类中导入#import“Project-Name-Swift.h”文件解决了这个问题。
I Change file DDXML.h and Work. 我更改文件DDXML.h和工作。
File: DDXML.h 文件:DDXML.h
Change: 更改:
#if TARGET_OS_IPHONE && 0 // Disabled by default
To: 至:
#if TARGET_OS_IPHONE && 1 // Disabled by default
这在我重命名一个类后经常发生,然后忘记在头文件中更新@class myclass(显然不会抛出编译错误。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.