I'm trying to do something like this:
public extension UIImage {
public convenience init(whatever: Int) {
UIGraphicsBeginImageContextWithOptions(...)
//...
let image = UIGraphicsGetImageFromCurrentContext()
UIGraphicsEndImageContext()
return image // <- impossible
}
}
But this is not possible as "nil" is the only valid return for an initializer... How do i do this?
For example, the Objtive-C method [UIImage imageNamed:] is a class method (that can return whatever it wants in Objective-C) and it was mapped to the swift initializer UIImage(named:).
init()
or even create a custom initializer to instantiate the view controller programmatically, and have it all setup with its subviews/outlets etc. But the only way is to use a factory method... – Xylidine