NSCoder: Unrecognized selector sent to instance

后端 未结 1 1537
傲寒
傲寒 2021-01-25 21:38

So, I\'m new to iOS and have been using online tutorials to learn the platform. The tutorials I\'m using are building apps with iOS 9 while I\'m using iOS 10. Because of that I

相关标签:
1条回答
  • 2021-01-25 21:38

    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.

    0 讨论(0)
提交回复
热议问题