diff --git a/LICENSE b/LICENSE index 0ea4d657..ae783e17 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009 Dailymotion - Olivier Poitrey +Copyright (c) 2009 Olivier Poitrey Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 89eb9e78..2f264952 100644 --- a/README.md +++ b/README.md @@ -58,25 +58,25 @@ it, et voila! How To Use It ------------- -### DMWebImageView as UIImageWeb Drop-In Replacement +### SDWebImageView as UIImageWeb Drop-In Replacement Most common use is in conjunction with an UITableView: - Place an UIImageView as a subview of your UITableViewCell in Interface Builder -- Set its class to DMImageView in the identity panel. +- Set its class to SDImageView in the identity panel. - Optionally set an image from your bundle to this UIImageView, it will be used as a placeholder image waiting for the real image to be downloaded. - In your tableView:cellForRowAtIndexPath: UITableViewDataSource method, invoke the setImageWithURL: - method of the DMWebImage view with the URL of the image to download + method of the SDWebImage view with the URL of the image to download Your done, everything will be handled for you, from parallel downloads to caching management. ### Asynchronous Image Downloader It is possible to use the NSOperation based image downloader independently. Just create an instance -of DMWebImageDownloader using its convenience constructor downloaderWithURL:target:action:. +of SDWebImageDownloader using its convenience constructor downloaderWithURL:target:action:. - downloader = [DMWebImageDownloader downloaderWithURL:url + downloader = [SDWebImageDownloader downloaderWithURL:url target:self action:@selector(downloadFinishedWithImage:)]; @@ -85,11 +85,11 @@ soon as the download of image will be completed (prepare not to be called from t ### Asynchronous Image Caching -It is also possible to use the NSOperation based image cache store independently. DMImageCache +It is also possible to use the NSOperation based image cache store independently. SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed asynchronous so it doesn't add unnecessary latency to the UI. -The DMImageCache class provides a singleton instance for convenience but you can create your own +The SDImageCache class provides a singleton instance for convenience but you can create your own instance if you want to create separated cache namespaces. To lookup the cache, you use the imageForKey: method. If the method returns nil, it means the cache @@ -97,15 +97,15 @@ doesn't currently own the image. You are thus responsible of generating and cach key is an application unique identifier for the image to cache. It is generally the absolute URL of the image. - UIImage *myCachedImage = [[DMImageCache sharedImageCache] imageFromKey:myCacheKey]; + UIImage *myCachedImage = [[SDImageCache sharedImageCache] imageFromKey:myCacheKey]; -By default DMImageCache will lookup the disk cache if an image can't be found in the memory cache. +By default SDImageCache will lookup the disk cache if an image can't be found in the memory cache. You can prevent this from happening by calling the alternative method imageFromKey:fromDisk: with a negative second argument. To store an image into the cache, you use the storeImage:forKey: method: - [[DMImageCache sharedImageCache] storeImage:myImage forKey:myCacheKey]; + [[SDImageCache sharedImageCache] storeImage:myImage forKey:myCacheKey]; By default, the image will be stored in memory cache as well as on disk cache (asynchronously). If you want only the memory cache, use the alternative method storeImage:forKey:toDisk: with a negative diff --git a/DMImageCache.h b/SDImageCache.h similarity index 78% rename from DMImageCache.h rename to SDImageCache.h index d2be8645..d8c2a63a 100644 --- a/DMImageCache.h +++ b/SDImageCache.h @@ -1,6 +1,6 @@ /* - * This file is part of the DMWebImage package. - * (c) Dailymotion - Olivier Poitrey + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -8,14 +8,14 @@ #import -@interface DMImageCache : NSObject +@interface SDImageCache : NSObject { NSMutableDictionary *memCache; NSString *diskCachePath; NSOperationQueue *cacheInQueue; } -+ (DMImageCache *)sharedImageCache; ++ (SDImageCache *)sharedImageCache; - (void)storeImage:(UIImage *)image forKey:(NSString *)key; - (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk; - (UIImage *)imageFromKey:(NSString *)key; diff --git a/DMImageCache.m b/SDImageCache.m similarity index 95% rename from DMImageCache.m rename to SDImageCache.m index ad40a015..6213612b 100644 --- a/DMImageCache.m +++ b/SDImageCache.m @@ -1,19 +1,19 @@ /* - * This file is part of the DMWebImage package. - * (c) Dailymotion - Olivier Poitrey + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -#import "DMImageCache.h" +#import "SDImageCache.h" #import static NSInteger cacheMaxCacheAge = 60*60*24*7; // 1 week -static DMImageCache *instance; +static SDImageCache *instance; -@implementation DMImageCache +@implementation SDImageCache #pragma mark NSObject @@ -81,11 +81,11 @@ static DMImageCache *instance; #pragma mark ImageCache (class methods) -+ (DMImageCache *)sharedImageCache ++ (SDImageCache *)sharedImageCache { if (instance == nil) { - instance = [[DMImageCache alloc] init]; + instance = [[SDImageCache alloc] init]; } return instance; diff --git a/DMWebImageDownloader.h b/SDWebImageDownloader.h similarity index 74% rename from DMWebImageDownloader.h rename to SDWebImageDownloader.h index c6f83999..5d20d28d 100644 --- a/DMWebImageDownloader.h +++ b/SDWebImageDownloader.h @@ -1,6 +1,6 @@ /* - * This file is part of the DMWebImage package. - * (c) Dailymotion - Olivier Poitrey + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -8,7 +8,7 @@ #import -@interface DMWebImageDownloader : NSOperation +@interface SDWebImageDownloader : NSOperation { NSURL *url; id target; diff --git a/DMWebImageDownloader.m b/SDWebImageDownloader.m similarity index 83% rename from DMWebImageDownloader.m rename to SDWebImageDownloader.m index bc9c7504..384764bb 100644 --- a/DMWebImageDownloader.m +++ b/SDWebImageDownloader.m @@ -1,16 +1,16 @@ /* - * This file is part of the DMWebImage package. - * (c) Dailymotion - Olivier Poitrey + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -#import "DMWebImageDownloader.h" +#import "SDWebImageDownloader.h" static NSOperationQueue *downloadQueue; -@implementation DMWebImageDownloader +@implementation SDWebImageDownloader @synthesize url, target, action; @@ -22,7 +22,7 @@ static NSOperationQueue *downloadQueue; + (id)downloaderWithURL:(NSURL *)url target:(id)target action:(SEL)action { - DMWebImageDownloader *downloader = [[[DMWebImageDownloader alloc] init] autorelease]; + SDWebImageDownloader *downloader = [[[SDWebImageDownloader alloc] init] autorelease]; downloader.url = url; downloader.target = target; downloader.action = action; diff --git a/DMWebImageView.h b/SDWebImageView.h similarity index 57% rename from DMWebImageView.h rename to SDWebImageView.h index 6a041221..f3a0f435 100644 --- a/DMWebImageView.h +++ b/SDWebImageView.h @@ -1,6 +1,6 @@ /* - * This file is part of the DMWebImage package. - * (c) Dailymotion - Olivier Poitrey + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -8,12 +8,12 @@ #import -@class DMWebImageDownloader; +@class SDWebImageDownloader; -@interface DMWebImageView : UIImageView +@interface SDWebImageView : UIImageView { UIImage *placeHolderImage; - DMWebImageDownloader *downloader; + SDWebImageDownloader *downloader; } - (void)setImageWithURL:(NSURL *)url; diff --git a/DMWebImageView.m b/SDWebImageView.m similarity index 74% rename from DMWebImageView.m rename to SDWebImageView.m index 6375128e..6878f064 100644 --- a/DMWebImageView.m +++ b/SDWebImageView.m @@ -1,16 +1,16 @@ /* - * This file is part of the DMWebImage package. - * (c) Dailymotion - Olivier Poitrey + * This file is part of the SDWebImage package. + * (c) Olivier Poitrey * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -#import "DMWebImageView.h" -#import "DMImageCache.h" -#import "DMWebImageDownloader.h" +#import "SDWebImageView.h" +#import "SDImageCache.h" +#import "SDWebImageDownloader.h" -@implementation DMWebImageView +@implementation SDWebImageView - (void)dealloc { @@ -41,7 +41,7 @@ self.image = placeHolderImage; } - UIImage *cachedImage = [[DMImageCache sharedImageCache] imageFromKey:[url absoluteString]]; + UIImage *cachedImage = [[SDImageCache sharedImageCache] imageFromKey:[url absoluteString]]; if (cachedImage) { @@ -49,7 +49,7 @@ } else { - downloader = [[DMWebImageDownloader downloaderWithURL:url target:self action:@selector(downloadFinishedWithImage:)] retain]; + downloader = [[SDWebImageDownloader downloaderWithURL:url target:self action:@selector(downloadFinishedWithImage:)] retain]; } } @@ -59,7 +59,7 @@ self.image = anImage; // Store the image in the cache - [[DMImageCache sharedImageCache] storeImage:anImage forKey:[downloader.url absoluteString]]; + [[SDImageCache sharedImageCache] storeImage:anImage forKey:[downloader.url absoluteString]]; // Free the downloader [downloader release];