【问题标题】:How do add core data to an existing project? [duplicate]如何将核心数据添加到现有项目中? [复制]
【发布时间】:2012-11-25 09:03:16
【问题描述】:

可能重复:
Adding Core Data to existing iPhone project

最初我创建项目时没有选择 coreData。经过一些开发后,我想使用核心数据进行数据管理。它给出了一些例外,例如

context = [[NSManagedObjectContext alloc] init]; 
CDAlbum *albumInfo = [NSEntityDescription insertNewObjectForEntityForName:@"CDAlbum" inManagedObjectContext:context]; 
albumInfo.albumName = @"MyAlbum"; 
CDPage *pageInfo = [NSEntityDescription insertNewObjectForEntityForName:@"CDPage" inManagedObjectContext:context]; 
pageInfo.message = @"It's my message"; 
pageInfo.pageId = @"123456"; 
pageInfo.album = albumInfo;
albumInfo.page = pageInfo;

'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'CDAlbum'

我认为这是因为链接。我该如何解决?

谢谢。

【问题讨论】:

  • 你能分享你的代码来创建持久存储协调器、托管对象模型和托管对象上下文吗
  • @SunilPandey : context = [[NSManagedObjectContext alloc] init]; CDAlbum *albumInfo = [NSEntityDescription insertNewObjectForEntityForName:@"CDAlbum" inManagedObjectContext:context]; albumInfo.albumName = @"我的相册"; CDPage *pageInfo = [NSEntityDescription insertNewObjectForEntityForName:@"CDPage" inManagedObjectContext:context]; pageInfo.message = @"这是我的消息"; pageInfo.pageId = @"123456"; pageInfo.album = 专辑信息; albumInfo.page = pageInfo;
  • 我认为你应该学习一些核心数据的基本概念。 raywenderlich.com/934/…检查这个

标签: iphone objective-c core-data


【解决方案1】:

1) 在您的项目中添加 CoreData 框架。 2) #import <CoreData/CoreData.h> 在您的 App_Prefix.pch 文件中。见this accepted answer to the same question

【讨论】:

    猜你喜欢
    • 2011-01-03
    • 1970-01-01
    • 2012-09-23
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    相关资源
    最近更新 更多