类扩展中的自定义初始化程序中的错误

时间:2016-03-23 11:44:38

标签: ios swift protocols extension-methods initializer

这是我的示例代码,它带来了我的问题:

protocol Decodable {
  init?(json: [String: AnyObject]) // remove this line will solve the problem
}

extension UIFont: Decodable { // remove `Decodable` will also solve the problem
  convenience init?(json: [String: AnyObject]) { // Error: Initialiser requirement 'init(json:)' can only be satisfied by a `required` initializer in the definition of non-final class 'UIFont'
    self.init(name: "whatever", size: 10)
  }
}

上面的代码使用Xcode 7.3& Swift 2.2

任何人都知道这个错误,为什么与协议定义的方法存在某种关系?

0 个答案:

没有答案
相关问题