Reputation: 1567
Is there a way I can check if there is valid image in the NSData I've loaded into my UIImage object?
The UIImage is loading in from NSData dataWithContentsOfURL:
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:MyURL]]];
Thanks
Upvotes: 1
Views: 3101
Reputation: 737
see here.
Check if NSURL returns 404
using NSURLConnection you can get the statuscode
Upvotes: 2
Reputation: 6149
It depends on what you mean by a valid image. If you do
[UIImage imageNamed:]
and the image isn't valid, it will return nil, so you can do:
UIImage *myImage = [UIImage imageNamed:@"yourImageName.png"]
if (myImage != nil) { ... }
Upvotes: 0