ios - 无法识别的选择器 - 异常

标签 ios swift caching

我有这个异常(exception):

2016-11-27 16:37:28.416 Participact[8846:501284] *** NSForwarding: warning: object 0x7ff90da33110 of class 'Participact.UserResult' does not implement methodSignatureForSelector: -- trouble ahead Unrecognized selector -[Participact.UserResult replacementObjectForKeyedArchiver:]

生成者:

let placesDataFinal = NSKeyedArchiver.archivedDataWithRootObject(self.userResults)
NSUserDefaults.standardUserDefaults().setObject(placesDataFinal, forKey: "places")

UserResults 是这个类:

class UserResult: JSONObject {
    lazy private(set) var taskId: Int? = self.deserializeJSON("TaskId")
    lazy private(set) var aggregato: Boolean? = self.deserializeJSON("Aggregato")
    lazy private(set) var tipo: String? = self.deserializeJSON("Tipo")
    lazy private(set) var valori: [String]? = self.deserializeJSON("Valori")
}

我认为修复方法:通过 NSObjectUserResult 继承,但我不能,因为它与 JSONObject 冲突。

我能做什么?

最佳答案

UserResult 类必须实现 NSCoding 协议(protocol)才能使用 NSKeyedArchiver 进行存档。

查看此 link关于如何实现协议(protocol),基本上你必须实现这些方法:

func encodeWithCoder(aCoder: NSCoder)
init(coder aDecoder: NSCoder)

关于ios - 无法识别的选择器 - 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40830881/

相关文章:

ios - 如何检测语言环境?

iphone - PerformSelectorInBackground 导致 EXC_BAD_ACCESS

ios - cellForRowAtIndexPath 中的 dequeueReusableCellWithIdentifier 中的单元格直到滚动才显示

php - file_get_contents 得到错误的结果

c++ - Map.erase() 抛出错误,为什么?

iphone - kCTSuperscriptAttributeName 不适用于使用下标和上标

ios - XCode 4.6显示了方法+(void)beginAnimations:(NSString *)animationID context:(void *)context的内存泄漏警告。

swift/iOS : How to access Object properties when type-casted from Protocol?

ios - 为什么滑动手势识别器会 swift 出错?

caching - RxJava 为 future 订阅者缓存最后一项