SWIFT 4.1 – Sub-class UIMAGE

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 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

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>

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4095 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.