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类的扩展上进行了分解.
The error pretty much says that if a function is declared in the extension than it can’t be overrIDden in this way
class Foo: UIImage {}extension Foo { convenIEnce init(bar :String) { self.init() }}var temp = Foo(bar: "Hello")
你可以尝试以这种方式实现欲望的结果.
总结以上是内存溢出为你收集整理的Swift 4.1 – 子类UIImage全部内容,希望文章能够帮你解决Swift 4.1 – 子类UIImage所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)