Tôi đang cố gắng mở rộng lớp NSDictionary trong Swift để chứa một NSDate được đặt trên init(). Khi tôi thêm init tùy chỉnh của tôi(), tôi nhận được lỗi biên dịch:Không thể ghi đè khởi tạo của NSDictionary trong Swift
'required' initializer 'init(dictionaryLiteral:)' must be provided by subclass of 'NSDictionary'
Tuy nhiên, khi tôi thêm rằng initializer sử dụng tự động hoàn tất, tôi nhận được lỗi sau:
Declarations from extensions cannot be overridden yet
Có cách để ghi đè lên initializer của NSDictionary hoặc Swift có thể không xử lý được chưa?
Đây là lớp học của tôi:
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")
}
}
Vì vậy, tôi đoán đó là chưa thể ghi đè lên initializer cho NSDictionary trong Swift. Trình biên dịch yêu cầu bạn ghi đè 'init (dictionaryLiteral :)' nhưng đồng thời không cho phép. Tôi thực sự hy vọng Swift sẽ bổ sung thêm khả năng sớm. – Mel
Apple lameness! –
Vẫn ** không ** cố định với Swift 4. –