Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Small cleanup and refactoring

  • Loading branch information...
commit fc3ee95a59aeb2df5a89a3f8a328457c825795b6 1 parent 140ec06
Magnus Ernstsson authored
22 Impl/GravatarUIImageFactory.m
View
@@ -59,6 +59,7 @@ -(void)makeRequest:(NSString *)request {
} else {
[self.delegate gravatarService:self didFailWithError:nil];
+ [self cleanUp];
}
}
@@ -81,6 +82,7 @@ -(void)requestUIImageByGravatarId:(NSString *)gravatarId size:(NSInteger) size {
} else {
[self.delegate gravatarService:self didFailWithError:nil];
+ [self cleanUp];
}
}
@@ -116,8 +118,7 @@ -(void)connection:(NSURLConnection *)connection
didFailWithError:(NSError *)error {
[self.delegate gravatarService:self didFailWithError:error];
- self.receivedData = nil;
- self.connection = nil;
+ [self cleanUp];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
@@ -125,14 +126,12 @@ -(void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self.delegate gravatarServiceDone:self
withImage:[UIImage imageWithData:self.receivedData]];
- self.receivedData = nil;
- self.connection = nil;
+ [self cleanUp];
}
-(void)cancelRequest {
-
- self.connection = nil;
- self.receivedData = nil;
+
+ [self cleanUp];
}
-(void)setConnection:(NSURLConnection *)newConnection {
@@ -142,10 +141,15 @@ -(void)setConnection:(NSURLConnection *)newConnection {
connection = [newConnection retain];
}
+-(void)cleanUp {
+ self.connection = nil;
+ self.delegate = nil;
+ self.receivedData = nil;
+}
+
-(void)dealloc {
- self.receivedData = nil;
- self.connection = nil;
+ [self cleanUp];
[super dealloc];
}
1  Interface/GravatarServiceDelegate.h
View
@@ -6,6 +6,7 @@
// Copyright 2010 Patchwork Solutions AB. All rights reserved.
//
+#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@protocol GravatarService;
2  Interface/GravatarServiceFactory.m
View
@@ -9,7 +9,6 @@
#import "GravatarServiceFactory.h"
#import "GravatarUIImageFactory.h"
-
@implementation GravatarServiceFactory
+(id<GravatarService>)requestUIImageByGravatarId:(NSString *)gravtarId
@@ -60,5 +59,4 @@ @implementation GravatarServiceFactory
return service;
}
-
@end
5 Interface/GravatarUIImageFactory.h
View
@@ -6,7 +6,6 @@
// Copyright 2010 Patchwork Solutions AB. All rights reserved.
//
-#import <Foundation/Foundation.h>
#import "GravatarService.h"
@protocol GravatarServiceDelegate;
@@ -17,7 +16,7 @@
NSURLConnection *connection;
}
-@property (assign) id<GravatarServiceDelegate> delegate;
+@property (retain) id<GravatarServiceDelegate> delegate;
@property (retain) NSMutableData *receivedData;
@property (retain) NSURLConnection *connection;
@@ -32,4 +31,6 @@
-(void)requestUIImageByEmail:(NSString *)gravatarId;
+-(void)cleanUp;
+
@end
4 gravatarlib.xcodeproj/project.pbxproj
View
@@ -220,7 +220,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
OTHER_LDFLAGS = "-ObjC";
PREBINDING = NO;
- SDKROOT = iphoneos4.1;
+ SDKROOT = iphoneos;
};
name = Debug;
};
@@ -233,7 +233,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
OTHER_LDFLAGS = "-ObjC";
PREBINDING = NO;
- SDKROOT = iphoneos4.1;
+ SDKROOT = iphoneos;
};
name = Release;
};
Please sign in to comment.
Something went wrong with that request. Please try again.