Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 232
cdub Avatar asked Nov 27 '13 09:11

cdub


2 Answers

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
like image 101
Edu Avatar answered Sep 20 '22 09:09

Edu


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.

like image 27
Jamal Zafar Avatar answered Sep 23 '22 09:09

Jamal Zafar