核心数据出错

时间:2014-09-10 15:06:05

标签: ios objective-c core-data xcode5

当我在我的实体Utente上添加autoLogin属性代码不起作用,如果我删除此属性代码工作,为什么??? PS:我需要新的属性,有人可以帮助我:)

Unresolved error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x10970aae0 {metadata={
    NSPersistenceFrameworkVersion = 479;
    NSStoreModelVersionHashes =     {
        Utente = ;
    };
    NSStoreModelVersionHashesVersion = 3;
    NSStoreModelVersionIdentifiers =     (
        ""
    );
    NSStoreType = SQLite;
    NSStoreUUID = "C879290E-F81B-4D22-B6FF-12F34B97820F";
    "_NSAutoVacuumLevel" = 2;
}, reason=The model used to open the store is incompatible with the one used to create the store}, {
    metadata =     {
        NSPersistenceFrameworkVersion = 479;
        NSStoreModelVersionHashes =         {
            Utente = ;
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =         (
            ""
        );
        NSStoreType = SQLite;
        NSStoreUUID = "C879290E-F81B-4D22-B6FF-12F34B97820F";
        "_NSAutoVacuumLevel" = 2;
    };
    reason = "The model used to open the store is incompatible with the one used to create the store";
}

代码:

 //caricamento DB
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext]; //the error signal is here
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"Utente" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];



NSManagedObject *matches = nil;

NSError *error;
NSArray *objects = [context executeFetchRequest:request
                                          error:&error];

if ([objects count] == 0)
{
    NSLog(@"No Email save");
}
else
{
    for (int i = 0; i < [objects count]; i++)
    {
        matches = objects[i];
        //NSManagedObject *o = objects[i];
        //[context deleteObject:o]; //cancella
        //[context save:&error];

        //email
         NSLog(@"email salvata : %@",[matches valueForKey:@"email"]);
        emailText.text=[matches valueForKey:@"email"];


        //password
        NSString * psw =[matches valueForKey:@"password"];
        if (psw)
        {
            NSLog(@"password salvata : %@",[matches valueForKey:@"password"]);
            passwordText.text=[matches valueForKey:@"password"];

            //auto-login
            NSString * psw =[matches valueForKey:@"autoLogin"];
            if (psw)
            {
                [self login:self];
            }
        }

1 个答案:

答案 0 :(得分:1)

事实上,一旦部署了集成Core Data的应用程序,生成的模型就会被版本化。

如果您需要向实体添加新属性,之前需要创建CoreData模型的新版本,方法是选择菜单“编辑器 - &gt;添加模型版本”,然后对您的实体进行更改

enter image description here

如果您的修改很简单(列删除,列添加...),CoreData可以处理轻量级迁移,但没有太多特定代码,但您需要在项目中保留CoreData模型的所有版本,以启用iOS执行现有商店的迁移。

Apple文档中详细介绍了所有内容,可在此处找到:https://developer.apple.com/library/ios/documentation/cocoa/Conceptual/CoreDataVersioning/Articles/Introduction.html

相关问题