gpt4 book ai didi

ios - 将属性类型从 Int16 更改为 Int64 时是否需要核心数据模型迁移

转载 作者:搜寻专家 更新时间:2023-10-31 23:00:38 24 4
gpt4 key购买 nike

我已将数据模型的属性类型从 Int16 更改为 Int64。它是否需要迁移,或者它会自 Action 为相同的数据类型 Int 工作。请指导。

最佳答案

是的,您可以更改属性类型并在核心数据中迁移您的数据存储,但为此,在创建/配置您的 NSPersistentStoreCoordinator 时,您需要设置一些我在下面提到的选项。这是我们在此处执行的 core-data 中调用 LightWeight Migration

使用以下代码更新您的 persistentStoreCoordinator 初始化方法。

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
// The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it.
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}

// Create the coordinator and store
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];

// *** add support for light weight migration ***
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
nil];

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"StoreName.sqlite"];
NSError *error = nil;
// *** Add support for lightweight migration by passing options value ***
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {

// Replace this with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}

return _persistentStoreCoordinator;
}

您可以在以下站点阅读有关核心数据迁移的更多信息。

1. Apple official documentation

2. Other site

关于ios - 将属性类型从 Int16 更改为 Int64 时是否需要核心数据模型迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36030857/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com