Authored by Jamie Pinkham
Committed by Olivier Poitrey

Added Mac OS X compatibility

@@ -41,7 +41,8 @@ static SDImageCache *instance; @@ -41,7 +41,8 @@ static SDImageCache *instance;
41 cacheInQueue.maxConcurrentOperationCount = 1; 41 cacheInQueue.maxConcurrentOperationCount = 1;
42 cacheOutQueue = [[NSOperationQueue alloc] init]; 42 cacheOutQueue = [[NSOperationQueue alloc] init];
43 cacheOutQueue.maxConcurrentOperationCount = 1; 43 cacheOutQueue.maxConcurrentOperationCount = 1;
44 - 44 +#if !TARGET_OS_IPHONE
  45 +#else
45 // Subscribe to app events 46 // Subscribe to app events
46 [[NSNotificationCenter defaultCenter] addObserver:self 47 [[NSNotificationCenter defaultCenter] addObserver:self
47 selector:@selector(clearMemory) 48 selector:@selector(clearMemory)
@@ -64,6 +65,7 @@ static SDImageCache *instance; @@ -64,6 +65,7 @@ static SDImageCache *instance;
64 object:nil]; 65 object:nil];
65 } 66 }
66 #endif 67 #endif
  68 +#endif
67 } 69 }
68 70
69 return self; 71 return self;
@@ -98,7 +100,7 @@ static SDImageCache *instance; @@ -98,7 +100,7 @@ static SDImageCache *instance;
98 { 100 {
99 const char *str = [key UTF8String]; 101 const char *str = [key UTF8String];
100 unsigned char r[CC_MD5_DIGEST_LENGTH]; 102 unsigned char r[CC_MD5_DIGEST_LENGTH];
101 - CC_MD5(str, strlen(str), r); 103 + CC_MD5(str, (CC_LONG)strlen(str), r);
102 NSString *filename = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", 104 NSString *filename = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
103 r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], r[11], r[12], r[13], r[14], r[15]]; 105 r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8], r[9], r[10], r[11], r[12], r[13], r[14], r[15]];
104 106
@@ -124,8 +126,14 @@ static SDImageCache *instance; @@ -124,8 +126,14 @@ static SDImageCache *instance;
124 UIImage *image = [[self imageFromKey:key fromDisk:YES] retain]; // be thread safe with no lock 126 UIImage *image = [[self imageFromKey:key fromDisk:YES] retain]; // be thread safe with no lock
125 if (image) 127 if (image)
126 { 128 {
  129 +#if !TARGET_OS_IPHONE
  130 + NSArray* representations = [image representations];
  131 + NSData* jpegData = [NSBitmapImageRep representationOfImageRepsInArray: representations usingType: NSJPEGFileType properties:nil];
  132 + [fileManager createFileAtPath:[self cachePathForKey:key] contents:jpegData attributes:nil];
  133 +#else
127 [fileManager createFileAtPath:[self cachePathForKey:key] contents:UIImageJPEGRepresentation(image, (CGFloat)1.0) attributes:nil]; 134 [fileManager createFileAtPath:[self cachePathForKey:key] contents:UIImageJPEGRepresentation(image, (CGFloat)1.0) attributes:nil];
128 [image release]; 135 [image release];
  136 +#endif
129 } 137 }
130 } 138 }
131 139
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 // Copyright 2010 Dailymotion. All rights reserved. 6 // Copyright 2010 Dailymotion. All rights reserved.
7 // 7 //
8 8
9 -#import <UIKit/UIKit.h> 9 +#import "SDWebImageCompat.h"
10 10
11 @class SDImageCache; 11 @class SDImageCache;
12 12
  1 +//
  2 +// SDWebImageCompat.h
  3 +// SDWebImageCompat
  4 +//
  5 +// Created by Jamie Pinkham on 3/15/11.
  6 +// Copyright 2011 __MyCompanyName__. All rights reserved.
  7 +//
  8 +
  9 +#import <TargetConditionals.h>
  10 +
  11 +#if !TARGET_OS_IPHONE
  12 +#import <AppKit/AppKit.h>
  13 +#ifndef UIImage
  14 +#define UIImage NSImage
  15 +#endif
  16 +#ifndef UIImageView
  17 +#define UIImageView NSImageView
  18 +#endif
  19 +#else
  20 +#import <UIKit/UIKit.h>
  21 +#endif
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 8
9 #import <Foundation/Foundation.h> 9 #import <Foundation/Foundation.h>
10 #import "SDWebImageDownloaderDelegate.h" 10 #import "SDWebImageDownloaderDelegate.h"
  11 +#import "SDWebImageCompat.h"
11 12
12 extern NSString *const SDWebImageDownloadStartNotification; 13 extern NSString *const SDWebImageDownloadStartNotification;
13 extern NSString *const SDWebImageDownloadStopNotification; 14 extern NSString *const SDWebImageDownloadStopNotification;
@@ -6,6 +6,8 @@ @@ -6,6 +6,8 @@
6 * file that was distributed with this source code. 6 * file that was distributed with this source code.
7 */ 7 */
8 8
  9 +#import "SDWebImageCompat.h"
  10 +
9 @class SDWebImageDownloader; 11 @class SDWebImageDownloader;
10 12
11 @protocol SDWebImageDownloaderDelegate <NSObject> 13 @protocol SDWebImageDownloaderDelegate <NSObject>
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 * file that was distributed with this source code. 6 * file that was distributed with this source code.
7 */ 7 */
8 8
9 -#import <UIKit/UIKit.h> 9 +#import "SDWebImageCompat.h"
10 #import "SDWebImageDownloaderDelegate.h" 10 #import "SDWebImageDownloaderDelegate.h"
11 #import "SDWebImageManagerDelegate.h" 11 #import "SDWebImageManagerDelegate.h"
12 #import "SDImageCacheDelegate.h" 12 #import "SDImageCacheDelegate.h"
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 * file that was distributed with this source code. 6 * file that was distributed with this source code.
7 */ 7 */
8 8
9 -#import <UIKit/UIKit.h> 9 +#import "SDWebImageCompat.h"
10 #import "SDWebImageManagerDelegate.h" 10 #import "SDWebImageManagerDelegate.h"
11 11
12 @interface UIImageView (WebCache) <SDWebImageManagerDelegate> 12 @interface UIImageView (WebCache) <SDWebImageManagerDelegate>