我正在尝试在
Swift中扩展类NSDictionary以包含在init()上设置的NSDate.当我添加自定义init()时,我得到编译器错误:
‘required’ initializer ‘init(dictionaryLiteral:)’ must be provided by
subclass of ‘NSDictionary’
Declarations from extensions cannot be overridden yet
有没有办法覆盖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") } }
Swift有一个官方扩展机制,用于向类添加方法,但是当子类重写扩展方法时,编译器会引发错误.但错误文本看起来很有希望(重点补充):
来自扩展的声明无法覆盖
悬挂“尚未”鼓励我相信Apple的工程师了解受保护的扩展模式等设计模式,并将更新Swift以支持它们.
校验
https://github.com/ksm/SwiftInFlux/blob/master/README.md#overriding-declarations-from-extensions
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。