Swift 4.1 – 子类UIImage
发布时间:2020-12-14 04:40:44 所属栏目:百科 来源:网络整理
导读:我在升级到 Swift 4.1后使用自定义init创建子类UIImage时,不支持覆盖扩展的非@ objc声明错误 class Foo: UIImage { init(bar: String) { } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } // Overriding
我在升级到
Swift 4.1后使用自定义init创建子类UIImage时,不支持覆盖扩展的非@ objc声明错误
class Foo: UIImage { init(bar: String) { } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } // Overriding non-@objc declarations from extensions is not supported required convenience init(imageLiteralResourceName name: String) { fatalError("init(imageLiteralResourceName:) has not been implemented") } } 谢谢你的帮助 解决方法extension UIImage { /// Creates an instance initialized with the given resource name. /// /// Do not call this initializer directly. Instead,initialize a variable or /// constant using an image literal. required public convenience init(imageLiteralResourceName name: String) } 此init方法在UIiamge类的扩展上进行了分解.
class Foo: UIImage { } extension Foo { convenience init(bar :String) { self.init() } } var temp = Foo(bar: "Hello") 你可以尝试以这种方式实现欲望的结果. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |