Receiver type is forward declaration

安稳与你 提交于 2020-01-01 07:36:14

问题


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?


回答1:


You must import CoreData/CoreData.h in the file Supporting Files/YourApp-Prefix.pch:

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import <CoreData/CoreData.h>
#endif



回答2:


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.




回答3:


Add this to the top of your .h or .m file

#import <CoreData/CoreData.h>



回答4:


I solved the issue by importing the #import "Project-Name-Swift.h" file in the Objective C class that uses a Swift class.




回答5:


I Change file DDXML.h and Work.

File: DDXML.h

Change:

#if TARGET_OS_IPHONE && 0 // Disabled by default

To:

#if TARGET_OS_IPHONE && 1 // Disabled by default



回答6:


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.)



来源:https://stackoverflow.com/questions/20238772/receiver-type-is-forward-declaration

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