Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue Unknown type name NSManagedObject

I'm trying to have a very simple Core Data. I have a ViewController.h like this :

#import <UIKit/UIKit.h>

@interface ViewController : UIResponder <UIApplicationDelegate>;

@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;

- (IBAction)boutonSave:(id)sender;

@end

and a ViewController.m like that :

#import "ViewController.h"

@implementation ViewController

@synthesize managedObjectContext = __managedObjectContext;
@synthesize managedObjectModel = __managedObjectModel;
@synthesize persistentStoreCoordinator = __persistentStoreCoordinator;

- (IBAction)boutonSave:(id)sender {
ViewController *viewController = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [viewController managedObjectContext];
NSManagedObject *newJournee; //THIS LINE IN ERROR
newJournee = [NSEntityDescription insertNewObjectForEntityForName:@"JourneeDeTravail" inManagedObjectContext:context];
[newJournee setValue:_displayStart.text forKey:@"debut"];
[newJournee setValue:_displayEnd.text forKey:@"fin"];    

}

But when creating newJournee, I have a red alert "Unknow type name 'NSManagedObject', did you mean NSManagedObjectModel ?" ??? It's my first Core Data so I certainly missed something obvious to you... but not to me ! Help !

like image 490
Fabien Lebas Avatar asked Jan 24 '12 23:01

Fabien Lebas


2 Answers

add CoreData.framework and import like below

#import <CoreData/CoreData.h>

hope it helps~

like image 179
Eric Kim Avatar answered Oct 04 '22 04:10

Eric Kim


sounds like you missed an #import

like image 30
Muad'Dib Avatar answered Oct 04 '22 04:10

Muad'Dib