When I use custom init to create a subclass of UIImage after upgrading to Swift 4.1, it does not support overriding the extended non-@objc declaration error
p>
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")
}
}
Thank you for your help
< div class="content-split">
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)
}
This in The it method is decomposed on the extension of the UIiamge class.
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")
You can try This way achieves the desired result.
When I use custom init to create a subclass of UIImage after upgrading to Swift 4.1, it does not support overriding the extended non-@objc declaration error
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")
}
}
Thank you Your help
ex tension 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)
}
This init method is performed on the extension of the UIiamge class Decomposition.
The error pretty much says that if a function is declared in the extension than it can’t be overridden in this way
blockquote>
class Foo: UIImage {
}
extension Foo {
convenience init(bar :String) {
self.init( )
}
}
var temp = Foo(bar: "Hello")
You can try to achieve the desired result in this way.< /p>