Got Unrecognized selector -replacementObjectForKeyedArchiver: crash when implementing NSCoding in Swift

前端 未结 1 984
闹比i
闹比i 2020-12-05 04:03

I created a Swift class that conforms to NSCoding. (Xcode 6 GM, Swift 1.0)

import Foundation

private var nextNonce = 1000

class Command: NSCoding {

    le         


        
相关标签:
1条回答
  • 2020-12-05 04:34

    Although Swift class works without inheritance, but in order to use NSCoding you must inherit from NSObject.

    class Command: NSObject, NSCoding {
        ...
    }
    

    Too bad the compiler error is not very informative :(

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