【问题标题】:[myclass encodeWithCoder:]: unrecognized selector sent to instance error while using NSUserDefaults[myclass encodeWithCoder:]:使用 NSUserDefaults 时无法识别的选择器发送到实例错误
【发布时间】:2013-06-26 19:52:11
【问题描述】:

我正在尝试用来自 restkit 的值填充字典。我在我的 restEngine.m 中使用 NSUserDefaults 保存字典

 NSDictionary *dict = [mappingResult dictionary];

                   [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:dict] forKey:kPopulateTableView ];
                   [[NSUserDefaults standardUserDefaults] synchronize];

当我构建应用程序时,它会因错误消息而中断:

"[myclass encodeWithCoder:]: 无法识别的选择器发送到实例"

我在这里做错了什么?

【问题讨论】:

    标签: ios nsdictionary restkit nsuserdefaults


    【解决方案1】:

    似乎在您的 NSDictionary dict 中保存了不可编码的对象。
    但是
    只有可编码对象才能与归档器一起使用。

    为了可编码,它们必须实现NSCoding protocol

    SO:myclass 需要实现 NSCoding


    有关更多信息,请阅读“存档和序列化编程指南”

    【讨论】:

    • 那么我应该在哪里使用 NSCoding 实现我的类?在我的休息引擎中或实际定义类的位置?对不起,我不熟悉 NSCoding
    • 在你的课上.. 它是一个定义 2 的协议?然后你必须提供的方法
    猜你喜欢
    • 1970-01-01
    • 2017-02-14
    • 2015-12-09
    • 1970-01-01
    • 2020-03-06
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多