如何更新我的新代码,以便我可以在 App Store 中取消存档旧 App 中的数据?

How to update my new code so that I can unarchive data from my old app in the App Store?

提问人:MPD 提问时间:12/7/2021 更新时间:12/7/2021 访问量:75

问:

我在 App Store 中有一个很旧的应用程序。我正在尝试编写更新版本。我的原始应用程序存档和未存档的数据如下。我现在无法弄清楚如何在更新的应用程序中访问这些数据。

- (void)saveGG
{
    NSMutableData *data = [[NSMutableData alloc] init];
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
    [archiver encodeObject:givens forKey:@"Present"];
    [archiver finishEncoding];
    [data writeToFile:[self dataFilePath] atomically:YES];
}

- (void)loadGG
{
    NSString *path = [self dataFilePath];
    if ([[NSFileManager defaultManager] fileExistsAtPath:path])
    {
        NSData *data = [[NSData alloc] initWithContentsOfFile:path];
        NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
        gifts = [unarchiver decodeObjectForKey:@"Present"];
        [unarchiver finishDecoding];
    }
    else
    {
        gifts = [[NSMutableArray alloc] initWithCapacity:20];
    }
iOS Swift Objective-C Xcode nskeyedunarchiver

评论

0赞 Matic Oblak 12/7/2021
在这种情况下,我会保持此代码不变。将其桥接到 Swift。在新版本中,我会检查此文件是否存在,如果存在,则开始迁移。迁移完成后,请删除此文件,此代码将永远不会再次执行。目标主要是此代码将不再受支持,而仅用于每个用户迁移一次。
0赞 MPD 12/7/2021
谢谢马蒂奇。我的问题是我无法弄清楚如何将这段代码桥接到 Swift。我还有原始应用程序中不存在的额外字段,因此我不会传输完全相似的字段。
0赞 Matic Oblak 12/7/2021
至于桥接到 Swift,你需要一个桥接头文件,然后在其中导入这个类的头文件,它应该公开这两个方法。有了它,你应该能够直接在 Swift 中调用方法并使用此数据。加载数据后,您应该在新类中手动输入数据,并将它们与新字段一起保存。

答: 暂无答案