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 !
add CoreData.framework and import like below
#import <CoreData/CoreData.h>
hope it helps~
sounds like you missed an #import
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With