2014-09-10 152 views
-1

當我在我的實體上添加autoLogin屬性Utente的代碼不工作,如果我刪除此屬性的代碼工作,爲什麼? 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

的[用於開實體店的模式是用來創建存儲的一個不兼容]可能重複(HTTP://計算器.com/questions/8881453/the-model-used-to-open-the-store-is-incompatible-with-one-used-to-create-the) – 2014-09-10 15:09:21

+0

好吧,我需要做的是正確的func ? – 2014-09-10 15:12:19

回答

1

事實上,一旦你部署它集成了核心數據的應用程序,生成的模型被版本。

如果您需要爲您的實體添加新屬性,那麼您需要通過選擇菜單「編輯器 - >添加模型版本」創建新版本的CoreData模型,然後對您的實體進行更改。

enter image description here

如果你的修改是簡單的(列刪除,列相加......),CoreData可以處理沒有太大的特定代碼的輕量級遷移,但是你需要在你的項目中的CoreData的所有版本模型,以使iOS能夠爲現有商店執行遷移。

所有在蘋果的文檔,它可以在這裏找到充分詳細:https://developer.apple.com/library/ios/documentation/cocoa/Conceptual/CoreDataVersioning/Articles/Introduction.html

+0

THX你交配:) – 2014-09-10 15:24:39

+0

只是1個問題,怎麼「菜單」XD? – 2014-09-10 15:25:29

+0

添加了屏幕截圖,當您編輯您的xcdatamodel文件時顯示此菜單 – cdescours 2014-09-10 15:28:53