【问题标题】:NSKeyedUnarchiver issue when moving model to framework [duplicate]将模型移动到框架时出现 NSKeyedUnarchiver 问题 [重复]
【发布时间】:2020-06-18 01:08:26
【问题描述】:

我已将部分代码移至单独的框架中,该框架包含应用程序用来将数据持久保存到 CoreData 的模型。现在,当我尝试启动应用程序并尝试从 CoreData 恢复状态时,我收到以下错误。

2020-06-17 21:01:42.549851-0400 Project[17576:2986881] [error] fault: exception raised during multi-threaded fetch *** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (Project.Track) for key (NS.objects) because no class named "Project.Track" was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target). If the class was renamed, use setClassName:forClass: to add a class translation mapping to NSKeyedUnarchiver ({
    "__NSCoderInternalErrorCode" = 4864;
})

在将代码拆分为单独的框架之前,它按预期工作。我尝试将框架导入到每个使用 CD 的类中,甚至尝试使用 Framework.Track 将其映射到类的新命名空间,但我仍然收到此错误。有没有人遇到过这种情况,如果有,您能否分享一些解决错误的见解?感谢您的帮助。

【问题讨论】:

    标签: ios core-data nskeyedarchiver nskeyedunarchiver swift-framework


    【解决方案1】:

    我找到了答案,它是异常指定的。我只需要使用应用程序的命名空间将类名设置为新导入的类,如下所示:

    NSKeyedUnarchiver.setClass(Track.self, forClassName: "Project.Track")

    希望对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2019-03-08
      • 2011-08-08
      • 2011-10-08
      • 1970-01-01
      • 1970-01-01
      • 2019-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多