ios 接收者类型为前向声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20238772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Receiver type is forward declaration
提问by cdub
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?
这是什么,我该如何解决?
回答by Edu
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 Jamal Zafar
By forward Declaration means you must be declaring class by @Class
. Import the Class in the .h/.m file and hope so it will resolve the issue.
通过前向声明意味着您必须通过@Class
. 在 .h/.m 文件中导入类,希望它能解决问题。
回答by Yup.
Add this to the top of your .h or .m file
将此添加到 .h 或 .m 文件的顶部
#import <CoreData/CoreData.h>
回答by Rudolf J
I solved the issue by importing the #import "Project-Name-Swift.h" file in the Objective C class that uses a Swift class.
我通过在使用 Swift 类的 Objective C 类中导入 #import "Project-Name-Swift.h" 文件解决了这个问题。
回答by Ed Filowat
This frequently happens to me after renaming a class, and then forgetting to update @class myclass in a header file (which obviously won't throw a compile error.)
这经常发生在我重命名一个类之后,然后忘记更新头文件中的 @class myclass (这显然不会引发编译错误。)
回答by Oseias gomes
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