From 825207d1d099d08d0353c53d63adb8a280335c0e Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Fri, 29 Nov 2013 11:43:02 -0500 Subject: [PATCH] Add imageURL property to remaining categories --- SDWebImage/MKAnnotationView+WebCache.h | 8 ++++++++ SDWebImage/MKAnnotationView+WebCache.m | 10 +++++++++- SDWebImage/UIButton+WebCache.h | 8 ++++++++ SDWebImage/UIButton+WebCache.m | 10 +++++++++- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/SDWebImage/MKAnnotationView+WebCache.h b/SDWebImage/MKAnnotationView+WebCache.h index fca8df0..2be81c5 100644 --- a/SDWebImage/MKAnnotationView+WebCache.h +++ b/SDWebImage/MKAnnotationView+WebCache.h @@ -14,6 +14,14 @@ */ @interface MKAnnotationView (WebCache) +/** + * Get the current image URL. + * + * Note that because of the limitations of categories this property can get out of sync + * if you use setImage: directly. + */ +- (NSURL *)imageURL; + /** * Set the imageView `image` with an `url`. * diff --git a/SDWebImage/MKAnnotationView+WebCache.m b/SDWebImage/MKAnnotationView+WebCache.m index c86a09d..c4c2f88 100644 --- a/SDWebImage/MKAnnotationView+WebCache.m +++ b/SDWebImage/MKAnnotationView+WebCache.m @@ -9,11 +9,18 @@ #import "MKAnnotationView+WebCache.h" #import "objc/runtime.h" +static char imageURLKey; static char operationKey; @implementation MKAnnotationView (WebCache) -- (void)setImageWithURL:(NSURL *)url { +- (NSURL *)imageURL; +{ + return objc_getAssociatedObject(self, &imageURLKey); +} + +- (void)setImageWithURL:(NSURL *)url +{ [self setImageWithURL:url placeholderImage:nil options:0 completed:nil]; } @@ -36,6 +43,7 @@ static char operationKey; - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { [self cancelCurrentImageLoad]; + objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); self.image = placeholder; if (url) { diff --git a/SDWebImage/UIButton+WebCache.h b/SDWebImage/UIButton+WebCache.h index 1f5d2c8..b663dfd 100644 --- a/SDWebImage/UIButton+WebCache.h +++ b/SDWebImage/UIButton+WebCache.h @@ -14,6 +14,14 @@ */ @interface UIButton (WebCache) +/** + * Get the current image URL. + * + * Note that because of the limitations of categories this property can get out of sync + * if you use setImage: directly. + */ +- (NSURL *)currentImageURL; + /** * Set the imageView `image` with an `url`. * diff --git a/SDWebImage/UIButton+WebCache.m b/SDWebImage/UIButton+WebCache.m index 7f849e7..785d7fc 100644 --- a/SDWebImage/UIButton+WebCache.m +++ b/SDWebImage/UIButton+WebCache.m @@ -9,11 +9,18 @@ #import "UIButton+WebCache.h" #import "objc/runtime.h" +static char imageURLKey; static char operationKey; @implementation UIButton (WebCache) -- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state { +- (NSURL *)currentImageURL; +{ + return objc_getAssociatedObject(self, &imageURLKey); +} + +- (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state +{ [self setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; } @@ -36,6 +43,7 @@ static char operationKey; - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { [self cancelCurrentImageLoad]; + objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); [self setImage:placeholder forState:state]; if (url) {