Core data 问题未知类型名称NSManagedObject

Core data 问题未知类型名称NSManagedObject,core-data,ios5,nsmanagedobject,Core Data,Ios5,Nsmanagedobject,我试图得到一个非常简单的核心数据。我有一个ViewController。h如下所示: #import <UIKit/UIKit.h> @interface ViewController : UIResponder <UIApplicationDelegate>; @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; @property (readonl

我试图得到一个非常简单的核心数据。我有一个ViewController。h如下所示:

#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
}


但在创建newJournee时,我有一个红色警报“未知类型名称‘NSManagedObject’,您是指NSManagedObjectModel吗?”???这是我的第一个核心数据,所以我肯定错过了一些显而易见的东西。。。但不是对我!救命啊

听起来你错过了一个#导入

添加CoreData.framework并导入如下内容

#import <CoreData/CoreData.h>
#导入

希望能有帮助~

别担心。一切似乎都很好

只需做一件事..转到您的ViewController.m文件并添加此行

#import "ViewController.h"
#import <CoreData/CoreData.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; //Error removed
newJournee = [NSEntityDescription insertNewObjectForEntityForName:@"JourneeDeTravail" inManagedObjectContext:context];
[newJournee setValue:_displayStart.text forKey:@"debut"];
[newJournee setValue:_displayEnd.text forKey:@"fin"];
#导入“ViewController.h”
#进口
@实现视图控制器
@综合managedObjectContext=u managedObjectContext;
@综合managedObjectModel=u managedObjectModel;
@合成persistentStoreCoordinator=\uuu persistentStoreCoordinator;
-(iAction)boutonSave:(id)发件人{
ViewController*ViewController=[[UIApplication sharedApplication]委托];
NSManagedObjectContext*上下文=[viewController managedObjectContext];
NSManagedObject*newJournee;//已删除错误
newJournee=[NSEntityDescription insertNewObjectForEntityForName:@“JourneeDeTravail”inManagedObjectContext:context];
[newJournee设置值:_displayStart.text forKey:@“首次登场”];
[newJournee设置值:_displayEnd.text forKey:@“fin”];

希望这能有所帮助。

听起来你错过了一个#importies,你是对的!在开始添加#import确实解决了它!谢谢!是的,导入时遇到了一个类似的问题-Prefix.pch-->///Prefix header///此文件的内容隐式包含在每个源文件的开头。//#import#ifndef IPHONE 5#0#warning“此项目仅使用iOS SDK 5.0及更高版本中可用的功能。”#endif#ifdef uu OBJC#import#import#endif
#import "ViewController.h"
#import <CoreData/CoreData.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; //Error removed
newJournee = [NSEntityDescription insertNewObjectForEntityForName:@"JourneeDeTravail" inManagedObjectContext:context];
[newJournee setValue:_displayStart.text forKey:@"debut"];
[newJournee setValue:_displayEnd.text forKey:@"fin"];