简体   繁体   English

轻量级迁移麻烦iOS

[英]Lightweight Migration hassle iOS

i am having a bit of a hassle, i created a new version of my context & made it the default one, after that i changed my code according to the apple docs and it looks like that now: 我有点麻烦,我创建了我的上下文的新版本并使其成为默认版本,之后我根据apple文档更改了我的代码,它现在看起来像这样:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{

    if (persistentStoreCoordinator != nil)
    {
        return persistentStoreCoordinator;
    }
    NSError *error = nil;
    persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"database.sqlite"];
    NSPersistentStoreCoordinator *psc = persistentStoreCoordinator;
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                             [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                             [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];


    BOOL success = [psc addPersistentStoreWithType:NSSQLiteStoreType
                                     configuration:nil URL:storeURL
                                           options:options error:&error];
    if (!success) {
        NSLog(@"Unresolved Error");
        abort();
    }

    return persistentStoreCoordinator;
}

but i get an error even though it is 1:1 the same code, in the line BOOL sucess i get an incompatible pointer to integer conversion 'BOOL' with 'NSPersistentstore' 但我得到一个错误,即使它是1:1相同的代码,在行BOOL sucess我得到一个incompatible pointer to integer conversion 'BOOL' with 'NSPersistentstore'

somehow the mapping has worked though and i get the new model in lets say 4 out of 5 times it works, the 5th it throws an error in that line. 不知何故,映射已经工作了,我得到了新模型,让我们说5次中有4次工作,第5次它会在该行中引发错误。

any ideas how to fix it? 任何想法如何解决它?

UPDATE i changed the code a bit and it now looks like that 更新我改变了一点代码,它现在看起来像那样

NSPersistentStore *store = [psc addPersistentStoreWithType:NSSQLiteStoreType
                                     configuration:nil URL:storeURL
                                           options:options error:&error];
if (!store) {
        NSLog(@"Unresolved Error");
        abort();
}

The warning and the error are two separate things. 警告和错误是两个不同的事情。

The warning is that you are treating a pointer as if it were a number. 警告是您将指针视为数字。 addPersistentStoreWithType:configuration:URL:options:error does not return a BOOL (which is essentially a number), it returns the NSPersistentStore object you are creating. addPersistentStoreWithType:configuration:URL:options:error不返回BOOL (实际上是一个数字),它返回您正在创建的NSPersistentStore对象。 Instead of a boolean success variable, you should be assigning the result to an NSPersistentStore * variable. 您应该将结果分配给NSPersistentStore *变量,而不是布尔成功变量。

In the case of failure, it returns nil and populates the error object. 在失败的情况下,它返回nil并填充error对象。 You can obtain more information about the error from this object, such as logging its localizedDescription . 您可以从此对象获取有关错误的更多信息,例如记录其localizedDescription

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM