Observe UIImage with KVO?
My model object has a UIImage *iconImg
that is often updated asynchronously. I want to allow instances of other classes to observe any changes to myModel.iconImg
elegantly. Right now, my asynchronous imag开发者_开发问答e fetch class takes a UIImage**
(yes, ugly, but it's working). The problem, however, is that messing with the UIImage via pointers bypasses any KVO I might have enjoyed using properties, so I have to use NSNotification which I'm not a big fan of. Here are the main requirements:
- I want to be able to load iconImg even when no views are ready to display it (ie no UIImageView is ready)
- Ideally, only the instances that have elected to observe the specific
myModel.iconImg
instance will be made aware of changes (unlike with Notifications where I currently have to filter) - I have several model classes with
iconImg
properties that all need to work this way, not just one I can change my image fetcher class if necessary (here's current signature):
+ (BOOL)asyncImageFetch:(UIImage**)anImagePtr withURL:(NSURL*)aUrl;
Not sure how clear that is, so let me know if I can elaborate on anything.
Thanks,
SteveFor anyone looking with similar requirements, take a look at SDWebImage (looks like Olivier Poitrey is the original author). Github repository here: https://github.com/rs/SDWebImage.
I've been using it and it's very nice.
精彩评论