UIImage, check if contain image UIImage, check if contain image ios ios

UIImage, check if contain image


You can check if it has any image data.

UIImage* image = [[UIImage alloc] init];CGImageRef cgref = [image CGImage];CIImage *cim = [image CIImage];if (cim == nil && cgref == NULL){    NSLog(@"no underlying data");}[image release];

Swift Version

let image = UIImage()let cgref = image.cgImagelet cim = image.ciImageif cim == nil && cgref == nil {    print("no underlying data")}


Check for cgImage or ciImage, in Swift 3

public extension UIImage {  public var hasContent: Bool {    return cgImage != nil || ciImage != nil  }}

CGImage: If the UIImage object was initialized using a CIImage object, the value of the property is NULL.

CIImage: If the UIImage object was initialized using a CGImageRef, the value of the property is nil.


Check with CGImageRef with itself wheather it contains null value means UIImage object not contains image.......