Here's my code
extension UIImage {
convenience init(color: UIColor, size: CGSize = CGSizeMake(1, 1)) {
let rect = CGRectMake(0, 0, size.width, size.height)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext()
CGContextSetFillColorWithColor(context, color.CGColor)
CGContextFillRect(context, rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
init(CGImage: image.CGImage!)
}
}
On init(CGImage: image.CGImage!)
, I get the error
Initializers may only be declared within a type
The dedicated initializer is called from the convenience initializer with self.init(...)
:
self.init(CGImage: image.CGImage!)
Without self.
(or super.
if you call the superclass initializer) the compiler mistakes init(...)
for the declaration of an init method.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments