Shamsiddin Shamsiddin - 5 months ago 20
iOS Question

Check if UIImage property got assigned or not?

I have an

UIImage
property, and after shooting image from iPhone camera I assigned image object to this property, otherwise not.
How can I check if this property contains image after shooting or not?
Below my code didn't help.

@interface MyViewController : UIView<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property(nonatomic, retain) UIImage *imageShot;
@end

@implementation MyViewController
@synthesize imageShot = _imageShot;

- (id)init {
self = [super init];
if (self) {
_imageShot = [[UiImage alloc] init];
}
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
self.imageShot = [info objectForKey:UIImagePickerControllerEditedImage];
}

- (void)buttonClick {
if (_imageShot) {

}
else {

}
}

@end

Answer

In your init, you should create shotedImage with nil instead of alloc'ing a new, empty image. That'll allow to perform tests like if (!shotedImage) (as nil == 0).