I have the following code where I want to see if a particular UIImageView (image) is set. If not then I want to display an error message.
if (image==nil) {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"No Image Selected"
delegate:nil
cancelButtonTitle:@"OK"
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet showInView:[[self view]window]];
[actionSheet autorelease];
}
let image: UIImage? = UIImage(contentsOfFile: filePath)if image != nil { return image!}
An object that manages image data in your app.
… imageView.image == nil ? Or, to check for empty images, CGSizeEqualToSize(imageView.image.size, CGSizeZero).
It may be tricky to figure out if (UIImageView *)image has been initialized with an image. You may want to check the image property:
if (image.image == nil)
This will work in the case where image.image==nil (UIImageView initialized by image not set) AND in the case where image==nil (since messages sent to nil return nil).
Beware local variables as well: Just because you never alloc/init image doesn't mean it will be nil.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With