I wrote this simple extension of UIImage to draw an image starting from a predefined color and a size.
This is the code:
extension UIImage {
class func image(color:UIColor, size:CGSize)->UIImage {
UIGraphicsBeginImageContextWithOptions(size, true, 2.0);
let context = UIGraphicsGetCurrentContext()
let rect = CGRectMake(0, 0, size.width, size.height)
color.set()
CGContextFillRect(context, rect)
var image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
If I launch this code in the ViewDidLoad method of a controller I get this error
Oct 31 16:48:02 iPhone Budjet_v2[3387] <Error>: CGContextSetFillColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Oct 31 16:48:02 iPhone Budjet_v2[3387] <Error>: CGContextSetStrokeColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
Oct 31 16:48:02 iPhone Budjet_v2[3387] <Error>: CGContextFillRects: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
fatal error: unexpectedly found nil while unwrapping an Optional value
I can't understand what's wrong with my code.