我正在尝试在 Swift 中扩展类 NSDictionary 以包含在 init() 上设置的 NSDate。添加自定义 init() 时,出现编译器错误:
“必需”初始化程序“init(dictionaryLiteral:)”必须由“NSDictionary”的子类提供
但是,当我使用自动完成添加该初始化程序时,我收到以下错误:
来自扩展的声明还不能被覆盖
有什么方法可以覆盖 NSDictionary 的初始化程序,或者 Swift 还不能处理吗?
这是我的课:
class DateParam : NSDictionary {
let date : NSDate
init(date: NSDate) {
super.init()
self.date = date
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
required convenience init(dictionaryLiteral elements: (NSCopying, AnyObject)...) {
fatalError("init(dictionaryLiteral:) has not been implemented")
}
}