开发者

Observe UIImage with KVO?

开发者 https://www.devze.com 2023-02-15 20:29 出处:网络
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 im

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:

  1. I want to be able to load iconImg even when no views are ready to display it (ie no UIImageView is ready)
  2. 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)
  3. I have several model classes with iconImg properties that all need to work this way, not just one
  4. 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,

Steve


For 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消