Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled compiling with ARC #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion EGOCache
Submodule EGOCache updated 2 files
+4 −0 EGOCache.h
+47 −16 EGOCache.m
10 changes: 10 additions & 0 deletions EGOImageButton/EGOImageButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,27 @@
@private
NSURL* imageURL;
UIImage* placeholderImage;
#if EGO_NO_ARC
id<EGOImageButtonDelegate> delegate;
#else
__unsafe_unretained id<EGOImageButtonDelegate> delegate;
#endif
}

- (id)initWithPlaceholderImage:(UIImage*)anImage; // delegate:nil
- (id)initWithPlaceholderImage:(UIImage*)anImage delegate:(id<EGOImageButtonDelegate>)aDelegate;

- (void)cancelImageLoad;

#if EGO_NO_ARC
@property(nonatomic,retain) NSURL* imageURL;
@property(nonatomic,retain) UIImage* placeholderImage;
@property(nonatomic,assign) id<EGOImageButtonDelegate> delegate;
#else
@property(nonatomic,strong) NSURL* imageURL;
@property(nonatomic,strong) UIImage* placeholderImage;
@property(nonatomic,unsafe_unretained) id<EGOImageButtonDelegate> delegate;
#endif
@end

@protocol EGOImageButtonDelegate<NSObject>
Expand Down
8 changes: 8 additions & 0 deletions EGOImageButton/EGOImageButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ - (id)initWithPlaceholderImage:(UIImage*)anImage delegate:(id<EGOImageButtonDele
- (void)setImageURL:(NSURL *)aURL {
if(imageURL) {
[[EGOImageLoader sharedImageLoader] removeObserver:self forURL:imageURL];
#if EGO_NO_ARC
[imageURL release];
#endif
imageURL = nil;
}

Expand All @@ -56,7 +58,11 @@ - (void)setImageURL:(NSURL *)aURL {
imageURL = nil;
return;
} else {
#if EGO_NO_ARC
imageURL = [aURL retain];
#else
imageURL = aURL;
#endif
}

UIImage* anImage = [[EGOImageLoader sharedImageLoader] imageForURL:aURL shouldLoadWithObserver:self];
Expand Down Expand Up @@ -102,7 +108,9 @@ - (void)dealloc {

self.imageURL = nil;
self.placeholderImage = nil;
#if EGO_NO_ARC
[super dealloc];
#endif
}

@end
9 changes: 9 additions & 0 deletions EGOImageLoader/EGOImageLoadConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
NSURLConnection* _connection;
NSTimeInterval _timeoutInterval;

#if EGO_NO_ARC
id<EGOImageLoadConnectionDelegate> _delegate;
#else
__unsafe_unretained id<EGOImageLoadConnectionDelegate> _delegate;
#endif
}

- (id)initWithImageURL:(NSURL*)aURL delegate:(id)delegate;
Expand All @@ -47,8 +51,13 @@
@property(nonatomic,readonly) NSData* responseData;
@property(nonatomic,readonly,getter=imageURL) NSURL* imageURL;

#if EGO_NO_ARC
@property(nonatomic,retain) NSURLResponse* response;
@property(nonatomic,assign) id<EGOImageLoadConnectionDelegate> delegate;
#else
@property(nonatomic,strong) NSURLResponse* response;
@property(nonatomic,unsafe_unretained) id<EGOImageLoadConnectionDelegate> delegate;
#endif

@property(nonatomic,assign) NSTimeInterval timeoutInterval; // Default is 30 seconds

Expand Down
13 changes: 12 additions & 1 deletion EGOImageLoader/EGOImageLoadConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ @implementation EGOImageLoadConnection

- (id)initWithImageURL:(NSURL*)aURL delegate:(id)delegate {
if((self = [super init])) {
#if EGO_NO_ARC
_imageURL = [aURL retain];
#else
_imageURL = aURL;
#endif
self.delegate = delegate;
_responseData = [[NSMutableData alloc] init];
self.timeoutInterval = 30;
Expand All @@ -55,7 +59,9 @@ - (void)start {
timeoutInterval:self.timeoutInterval];
[request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
_connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
#if EGO_NO_ARC
[request release];
#endif
}

- (void)cancel {
Expand Down Expand Up @@ -98,13 +104,18 @@ - (void)dealloc {
self.delegate = nil;

#if __EGOIL_USE_BLOCKS
[handlers release], handlers = nil;
#if EGO_NO_ARC
[handlers release];
#endif
handlers = nil;
#endif

#if EGO_NO_ARC
[_connection release];
[_imageURL release];
[_responseData release];
[super dealloc];
#endif
}

@end
10 changes: 10 additions & 0 deletions EGOImageLoader/EGOImageLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
#define __EGOIL_USE_NOTIF 1
#endif

#ifdef __has_feature
#define EGO_NO_ARC !__has_feature(objc_arc)
#else
#define EGO_NO_ARC 1
#endif

@protocol EGOImageLoaderObserver;
@interface EGOImageLoader : NSObject/*<NSURLConnectionDelegate>*/ {
@private
Expand Down Expand Up @@ -69,7 +75,11 @@
- (void)clearCacheForURL:(NSURL*)aURL;
- (void)clearCacheForURL:(NSURL*)aURL style:(NSString*)style;

#if EGO_NO_ARC
@property(nonatomic,retain) NSDictionary* currentConnections;
#else
@property(nonatomic,strong) NSDictionary* currentConnections;
#endif
@end

@protocol EGOImageLoaderObserver<NSObject>
Expand Down
49 changes: 42 additions & 7 deletions EGOImageLoader/EGOImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,18 @@ - (id)init {
}

- (EGOImageLoadConnection*)loadingConnectionForURL:(NSURL*)aURL {
#if EGO_NO_ARC
EGOImageLoadConnection* connection = [[self.currentConnections objectForKey:aURL] retain];
#else
EGOImageLoadConnection* connection = [self.currentConnections objectForKey:aURL];
#endif
if(!connection) return nil;
else return [connection autorelease];
else {
#if EGO_NO_ARC
[connection autorelease];
#endif
return connection;
}
}

- (void)cleanUpConnection:(EGOImageLoadConnection*)connection {
Expand All @@ -98,7 +107,10 @@ - (void)cleanUpConnection:(EGOImageLoadConnection*)connection {

[connectionsLock lock];
[currentConnections removeObjectForKey:connection.imageURL];
self.currentConnections = [[currentConnections copy] autorelease];
self.currentConnections = [currentConnections copy];
#if EGO_NO_ARC
[self.currentConnections autorelease];
#endif
[connectionsLock unlock];
}

Expand Down Expand Up @@ -131,10 +143,15 @@ - (EGOImageLoadConnection*)loadImageForURL:(NSURL*)aURL {

[connectionsLock lock];
[currentConnections setObject:connection forKey:aURL];
self.currentConnections = [[currentConnections copy] autorelease];
self.currentConnections = [currentConnections copy];
#if EGO_NO_ARC
[self.currentConnections autorelease];
#endif
[connectionsLock unlock];
[connection performSelector:@selector(start) withObject:nil afterDelay:0.01];
#if EGO_NO_ARC
[connection release];
#endif

return connection;
}
Expand Down Expand Up @@ -212,14 +229,20 @@ - (void)loadImageForURL:(NSURL*)aURL style:(NSString*)style styler:(UIImage* (^)
if(styler) {
UIImage* (^stylerCopy)(UIImage* image) = [styler copy];
[handler setObject:stylerCopy forKey:kStylerKey];
#if EGO_NO_ARC
[stylerCopy release];
#endif
}

#if EGO_NO_ARC
[handler release];
#endif
}

[[handler objectForKey:kCompletionsKey] addObject:completionCopy];
#if EGO_NO_ARC
[completionCopy release];
#endif
}
}
#endif
Expand Down Expand Up @@ -252,7 +275,10 @@ - (void)imageLoadConnectionDidFinishLoading:(EGOImageLoadConnection *)connection
[[EGOCache currentCache] setData:connection.responseData forKey:keyForURL(connection.imageURL,nil) withTimeoutInterval:604800];

[currentConnections removeObjectForKey:connection.imageURL];
self.currentConnections = [[currentConnections copy] autorelease];
self.currentConnections = [currentConnections copy];
#if EGO_NO_ARC
[self.currentConnections autorelease];
#endif

#if __EGOIL_USE_NOTIF
NSNotification* notification = [NSNotification notificationWithName:kImageNotificationLoaded(connection.imageURL)
Expand All @@ -274,7 +300,10 @@ - (void)imageLoadConnectionDidFinishLoading:(EGOImageLoadConnection *)connection

- (void)imageLoadConnection:(EGOImageLoadConnection *)connection didFailWithError:(NSError *)error {
[currentConnections removeObjectForKey:connection.imageURL];
self.currentConnections = [[currentConnections copy] autorelease];
self.currentConnections = [currentConnections copy];
#if EGO_NO_ARC
[self.currentConnections autorelease];
#endif

#if __EGOIL_USE_NOTIF
NSNotification* notification = [NSNotification notificationWithName:kImageNotificationLoadFailed(connection.imageURL)
Expand Down Expand Up @@ -329,9 +358,15 @@ - (void)dealloc {
#endif

self.currentConnections = nil;
[currentConnections release], currentConnections = nil;
[connectionsLock release], connectionsLock = nil;
#if EGO_NO_ARC
[currentConnections release];
[connectionsLock release];
#endif
currentConnections = nil;
connectionsLock = nil;
#if EGO_NO_ARC
[super dealloc];
#endif
}

@end
8 changes: 8 additions & 0 deletions EGOImageView/EGOImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
@private
NSURL* imageURL;
UIImage* placeholderImage;
#if EGO_NO_ARC
id<EGOImageViewDelegate> delegate;
#else
__unsafe_unretained id<EGOImageViewDelegate> delegate;
#endif
}

- (id)initWithPlaceholderImage:(UIImage*)anImage; // delegate:nil
Expand All @@ -42,7 +46,11 @@

@property(nonatomic,retain) NSURL* imageURL;
@property(nonatomic,retain) UIImage* placeholderImage;
#if EGO_NO_ARC
@property(nonatomic,assign) id<EGOImageViewDelegate> delegate;
#else
@property(nonatomic,unsafe_unretained) id<EGOImageViewDelegate> delegate;
#endif
@end

@protocol EGOImageViewDelegate<NSObject>
Expand Down
8 changes: 8 additions & 0 deletions EGOImageView/EGOImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ - (id)initWithPlaceholderImage:(UIImage*)anImage delegate:(id<EGOImageViewDelega
- (void)setImageURL:(NSURL *)aURL {
if(imageURL) {
[[EGOImageLoader sharedImageLoader] removeObserver:self forURL:imageURL];
#if EGO_NO_ARC
[imageURL release];
#endif
imageURL = nil;
}

Expand All @@ -55,7 +57,11 @@ - (void)setImageURL:(NSURL *)aURL {
imageURL = nil;
return;
} else {
#if EGO_NO_ARC
imageURL = [aURL retain];
#else
imageURL = aURL;
#endif
}

[[EGOImageLoader sharedImageLoader] removeObserver:self];
Expand Down Expand Up @@ -107,7 +113,9 @@ - (void)dealloc {
self.delegate = nil;
self.imageURL = nil;
self.placeholderImage = nil;
#if EGO_NO_ARC
[super dealloc];
#endif
}

@end