将NSEntity添加到NSOrderedSet时出错

Len_X

我的CoreData结构中有2个实体,它们之间存在一对多关系。在主实体中,我有一个NSOrderdSet,每次进行新保存时,我都想在NSOrderdSet中添加并保存第二个实体,但是出现错误。这是我的代码:

//main Entity 
class Project : NSManagedObject {
func requestAddNewWeek (value: WeekContent) {
let mutableCopyOfSet = projectContent?.mutableCopy() as! NSMutableOrderdSet
mutableCopyOfSet.addObject(value)
projectContent = mutableCopyOfSet.copy() as ? NSOderedSet
}
}

// ViewController where the save occurs
class SetupWeekViewController {
var project : Project?

@IBAction func saveButton (sender : AnyObject) {
 let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let managedContext : NSManagedObjectContext = appDelegate.managedObjectContext
 let entity = NSEntityDescription.entityForName("Content", inManagedObjectContext:managedObjectContext
//Here is where the error happens
project!requestAddNewWeek(newWeek)

managedContext.save()
}

//这是我得到的错误

2015-12-08 11:07:13.392 MySightwords[1998:189666] CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///Users/Len/Library/Developer/CoreSimulator/Devices/0215DFE7-14EA-459F-991C-5ABF8020712D/data/Containers/Data/Application/7A509174-D568-4CCE-8A3D-9710FF80A9BF/Documents/SingleViewCoreData.sqlite options:(null) ... returned error Error Domain=NSCocoaErrorDomain Code=134100 "(null)" UserInfo={metadata={
    NSPersistenceFrameworkVersion = 640;
    NSStoreModelVersionHashes =     {
        Content = <16a6b5d3 e57d053c f85d1afa 2efe7c04 8da974e7 127f2c6b 847ea2f0 b63d732f>;
        Project = <97588fff 696dabc6 896ec617 564b473f f3bc9bdc e6c891b3 84519149 9319c454>;
        Sightwords = <6bf96219 adc3369d 4eec0597 b40472c3 d3af6a61 3d17bd5d 117885f4 509ecd2e>;
    };
    NSStoreModelVersionHashesVersion = 3;
    NSStoreModelVersionIdentifiers =     (
        ""
    );
    NSStoreType = SQLite;
    NSStoreUUID = "270A2DB1-BFDA-41A3-B044-DFBA717A1BDD";
    "_NSAutoVacuumLevel" = 2;
}, reason=The model used to open the store is incompatible with the one used to create the store} with userInfo dictionary {
    metadata =     {
        NSPersistenceFrameworkVersion = 640;
        NSStoreModelVersionHashes =         {
            Content = <16a6b5d3 e57d053c f85d1afa 2efe7c04 8da974e7 127f2c6b 847ea2f0 b63d732f>;
            Project = <97588fff 696dabc6 896ec617 564b473f f3bc9bdc e6c891b3 84519149 9319c454>;
            Sightwords = <6bf96219 adc3369d 4eec0597 b40472c3 d3af6a61 3d17bd5d 117885f4 509ecd2e>;
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =         (
            ""
        );
        NSStoreType = SQLite;
        NSStoreUUID = "270A2DB1-BFDA-41A3-B044-DFBA717A1BDD";
        "_NSAutoVacuumLevel" = 2;
    };
    reason = "The model used to open the store is incompatible with the one used to create the store";
}
2015-12-08 11:07:13.396 MySightwords[1998:189666] Unresolved error Error Domain=YOUR_ERROR_DOMAIN Code=9999 "Failed to initialize the application's saved data" UserInfo={NSLocalizedDescription=Failed to initialize the application's saved data, NSLocalizedFailureReason=There was an error creating or loading the application's saved data., NSUnderlyingError=0x7ff7025e9200 {Error Domain=NSCocoaErrorDomain Code=134100 "(null)" UserInfo={metadata={
    NSPersistenceFrameworkVersion = 640;
    NSStoreModelVersionHashes =     {
        Content = <16a6b5d3 e57d053c f85d1afa 2efe7c04 8da974e7 127f2c6b 847ea2f0 b63d732f>;
        Project = <97588fff 696dabc6 896ec617 564b473f f3bc9bdc e6c891b3 84519149 9319c454>;
        Sightwords = <6bf96219 adc3369d 4eec0597 b40472c3 d3af6a61 3d17bd5d 117885f4 509ecd2e>;
    };
    NSStoreModelVersionHashesVersion = 3;
    NSStoreModelVersionIdentifiers =     (
        ""
    );
    NSStoreType = SQLite;
    NSStoreUUID = "270A2DB1-BFDA-41A3-B044-DFBA717A1BDD";
    "_NSAutoVacuumLevel" = 2;
}, reason=The model used to open the store is incompatible with the one used to create the store}}}, [NSLocalizedDescription: Failed to initialize the application's saved data, NSLocalizedFailureReason: There was an error creating or loading the application's saved data., NSUnderlyingError: Error Domain=NSCocoaErrorDomain Code=134100 "(null)" UserInfo={metadata={
    NSPersistenceFrameworkVersion = 640;
    NSStoreModelVersionHashes =     {
        Content = <16a6b5d3 e57d053c f85d1afa 2efe7c04 8da974e7 127f2c6b 847ea2f0 b63d732f>;
        Project = <97588fff 696dabc6 896ec617 564b473f f3bc9bdc e6c891b3 84519149 9319c454>;
        Sightwords = <6bf96219 adc3369d 4eec0597 b40472c3 d3af6a61 3d17bd5d 117885f4 509ecd2e>;
    };
    NSStoreModelVersionHashesVersion = 3;
    NSStoreModelVersionIdentifiers =     (
        ""
    );
    NSStoreType = SQLite;
    NSStoreUUID = "270A2DB1-BFDA-41A3-B044-DFBA717A1BDD";
    "_NSAutoVacuumLevel" = 2;
}, reason=The model used to open the store is incompatible with the one used to create the store}]
(lldb) 
巴拉吉·康达拉莱(Balaji Kondalrayal)

这是由于您的模型的更改。

从模拟器中删除该应用程序,然后对您的项目进行清理。

注意:这仅用于开发。对于生产,您需要实施某种迁移。Google的“核心数据迁移”,最简单的轻量级迁移。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

尝试将parserHook添加到MediaWiki时出错

来自分类Dev

将补丁添加到补丁集时出错

来自分类Dev

将add_header添加到nginx时出错

来自分类Dev

尝试将android平台添加到Cordova时出错

来自分类Dev

为什么在将变量添加到ArrayList时出错?

来自分类Dev

将tableadapter添加到数据集时出错

来自分类Dev

将CSRF令牌添加到Laravel表单时出错

来自分类Dev

将ListView添加到片段时出错

来自分类Dev

将CardView添加到布局时出错

来自分类Dev

我将library()添加到if函数时出错

来自分类Dev

将日期添加到数据库时出错

来自分类Dev

将JPA存储库添加到Spring时出错

来自分类Dev

将Google登录添加到网站时出错

来自分类Dev

将tableadapter添加到数据集时出错

来自分类Dev

将CardView添加到布局时出错

来自分类Dev

将枚举类型添加到Swift数组时出错

来自分类Dev

尝试将parserHook添加到MediaWiki时出错

来自分类Dev

尝试将视图添加到RelativeLayout时出错

来自分类Dev

将事件列表添加到画布时出错

来自分类Dev

将CoreData添加到现有项目时出错

来自分类Dev

将add_header添加到nginx时出错

来自分类Dev

为什么在将变量添加到ArrayList时出错?

来自分类Dev

将Facebook SDK添加到android项目时出错

来自分类Dev

将GameObject添加到类中的列表时出错

来自分类Dev

将Google登录添加到网站时出错

来自分类Dev

将FIRST记录添加到表时出错

来自分类Dev

将项目添加到网格时出错

来自分类Dev

将iOS平台添加到phonegap项目时出错

来自分类Dev

将数字添加到表格中时出错