NSCoder: Unrecognized selector sent to instance

一笑奈何 提交于 2019-12-02 09:28:34

With the help of a couple of users and some added searching, I was able to figure out the cause of my problem.

Per the suggestion of the previously mentioned users, I added the NSCoding protocol to my CalendarEvent class.

class CalendarEvent : NSObject, NSCoding {
    ....
}

Unfortunately, that didn't completely fix the issue, but it was a start. A few errors and a quick search showed me that I had to change this:

init(withCoder coder : NSCoder){
    ....
}
func encodeWithCoder(coder : NSCoder){
    ....
}

to this:

required init(coder : NSCoder) {
    ....
}
func encode(with aCoder : NSCoder) {
    ....
}

After making those changes, my code ran perfectly fine.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!