Convert getters / setters to obj-c 2.0 properties
Stop retaining delegate
Showing
5 changed files
with
31 additions
and
124 deletions
| @@ -109,14 +109,6 @@ | @@ -109,14 +109,6 @@ | ||
| 109 | 109 | ||
| 110 | #pragma mark delegate configuration | 110 | #pragma mark delegate configuration |
| 111 | 111 | ||
| 112 | -// Delegate will get messages when the request completes, fails or when authentication is required | ||
| 113 | -- (void)setDelegate:(id)newDelegate; | ||
| 114 | - | ||
| 115 | -// upload progress delegate (usually an NSProgressIndicator) is sent information on upload progress | ||
| 116 | -- (void)setUploadProgressDelegate:(id)newDelegate; | ||
| 117 | - | ||
| 118 | -// download progress delegate (usually an NSProgressIndicator) is sent information on download progress | ||
| 119 | -- (void)setDownloadProgressDelegate:(id)newDelegate; | ||
| 120 | 112 | ||
| 121 | #pragma mark setup request | 113 | #pragma mark setup request |
| 122 | 114 | ||
| @@ -132,32 +124,8 @@ | @@ -132,32 +124,8 @@ | ||
| 132 | // When set, username and password will be presented for HTTP authentication | 124 | // When set, username and password will be presented for HTTP authentication |
| 133 | - (void)setUsername:(NSString *)newUsername andPassword:(NSString *)newPassword; | 125 | - (void)setUsername:(NSString *)newUsername andPassword:(NSString *)newPassword; |
| 134 | 126 | ||
| 135 | -// When true, authentication information will automatically be stored in (and re-used from) the keychain | ||
| 136 | -- (void)setUsesKeychain:(BOOL)shouldUseKeychain; | ||
| 137 | - | ||
| 138 | -//the results of this request will be saved to downloadDestinationPath, if it is set | ||
| 139 | -- (void)setDownloadDestinationPath:(NSString *)newDestinationPath; | ||
| 140 | - | ||
| 141 | -- (NSString *)downloadDestinationPath; | ||
| 142 | - | ||
| 143 | -// This selector will be called on the delegate when the request completes successfully | ||
| 144 | -- (void)setDidFinishSelector:(SEL)selector; | ||
| 145 | - | ||
| 146 | -// This selector will be called on the delegate when the request fails | ||
| 147 | -- (void)setDidFailSelector:(SEL)selector; | ||
| 148 | - | ||
| 149 | #pragma mark get information about this request | 127 | #pragma mark get information about this request |
| 150 | 128 | ||
| 151 | -// Accessors for getting information about the request (useful for auth dialogs) | ||
| 152 | -- (NSString *)authenticationRealm; | ||
| 153 | -- (NSString *)host; | ||
| 154 | - | ||
| 155 | -// Contains a description of the error that occurred if the request failed | ||
| 156 | -- (NSError *)error; | ||
| 157 | -- (void)setError:(NSError *)newError; | ||
| 158 | - | ||
| 159 | -// Will be true when the request is complete (success or failure) | ||
| 160 | -- (BOOL)complete; | ||
| 161 | - (BOOL)isFinished; //Same thing, for NSOperationQueues to read | 129 | - (BOOL)isFinished; //Same thing, for NSOperationQueues to read |
| 162 | 130 | ||
| 163 | // Get total amount of data received so far for this request | 131 | // Get total amount of data received so far for this request |
| @@ -230,12 +198,17 @@ | @@ -230,12 +198,17 @@ | ||
| 230 | + (void)removeCredentialsForHost:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm; | 198 | + (void)removeCredentialsForHost:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm; |
| 231 | 199 | ||
| 232 | 200 | ||
| 233 | - | 201 | +@property (retain,readonly) NSURL *url; |
| 234 | - | 202 | +@property (assign) id delegate; |
| 235 | - | 203 | +@property (assign) NSObject *uploadProgressDelegate; |
| 236 | - | 204 | +@property (assign) NSObject *downloadProgressDelegate; |
| 237 | - | 205 | +@property (assign) BOOL usesKeychain; |
| 238 | - | 206 | +@property (retain) NSString *downloadDestinationPath; |
| 207 | +@property (assign) SEL didFinishSelector; | ||
| 208 | +@property (assign) SEL didFailSelector; | ||
| 209 | +@property (retain,readonly) NSString *authenticationRealm; | ||
| 210 | +@property (retain) NSError *error; | ||
| 211 | +@property (assign,readonly) BOOL complete; | ||
| 239 | 212 | ||
| 240 | 213 | ||
| 241 | @end | 214 | @end |
| @@ -25,8 +25,12 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | @@ -25,8 +25,12 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | ||
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | + | ||
| 29 | + | ||
| 28 | @implementation ASIHTTPRequest | 30 | @implementation ASIHTTPRequest |
| 29 | 31 | ||
| 32 | + | ||
| 33 | + | ||
| 30 | #pragma mark init / dealloc | 34 | #pragma mark init / dealloc |
| 31 | 35 | ||
| 32 | - (id)initWithURL:(NSURL *)newURL | 36 | - (id)initWithURL:(NSURL *)newURL |
| @@ -51,6 +55,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | @@ -51,6 +55,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | ||
| 51 | usesKeychain = NO; | 55 | usesKeychain = NO; |
| 52 | didFinishSelector = @selector(requestFinished:); | 56 | didFinishSelector = @selector(requestFinished:); |
| 53 | didFailSelector = @selector(requestFailed:); | 57 | didFailSelector = @selector(requestFailed:); |
| 58 | + delegate = nil; | ||
| 54 | return self; | 59 | return self; |
| 55 | } | 60 | } |
| 56 | 61 | ||
| @@ -67,9 +72,6 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | @@ -67,9 +72,6 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | ||
| 67 | } | 72 | } |
| 68 | [self cancelLoad]; | 73 | [self cancelLoad]; |
| 69 | [error release]; | 74 | [error release]; |
| 70 | - [delegate release]; | ||
| 71 | - [uploadProgressDelegate release]; | ||
| 72 | - [downloadProgressDelegate release]; | ||
| 73 | [postData release]; | 75 | [postData release]; |
| 74 | [fileData release]; | 76 | [fileData release]; |
| 75 | [requestHeaders release]; | 77 | [requestHeaders release]; |
| @@ -83,26 +85,6 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | @@ -83,26 +85,6 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | ||
| 83 | [super dealloc]; | 85 | [super dealloc]; |
| 84 | } | 86 | } |
| 85 | 87 | ||
| 86 | -#pragma mark delegate configuration | ||
| 87 | - | ||
| 88 | -- (void)setDelegate:(id)newDelegate | ||
| 89 | -{ | ||
| 90 | - [delegate release]; | ||
| 91 | - delegate = [newDelegate retain]; | ||
| 92 | -} | ||
| 93 | - | ||
| 94 | -- (void)setUploadProgressDelegate:(id)newDelegate | ||
| 95 | -{ | ||
| 96 | - [uploadProgressDelegate release]; | ||
| 97 | - uploadProgressDelegate = [newDelegate retain]; | ||
| 98 | -} | ||
| 99 | - | ||
| 100 | -- (void)setDownloadProgressDelegate:(id)newDelegate | ||
| 101 | -{ | ||
| 102 | - [downloadProgressDelegate release]; | ||
| 103 | - downloadProgressDelegate = [newDelegate retain]; | ||
| 104 | -} | ||
| 105 | - | ||
| 106 | 88 | ||
| 107 | #pragma mark setup request | 89 | #pragma mark setup request |
| 108 | 90 | ||
| @@ -139,67 +121,10 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | @@ -139,67 +121,10 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | ||
| 139 | password = [newPassword retain]; | 121 | password = [newPassword retain]; |
| 140 | } | 122 | } |
| 141 | 123 | ||
| 142 | -- (void)setUsesKeychain:(BOOL)shouldUseKeychain | ||
| 143 | -{ | ||
| 144 | - usesKeychain = shouldUseKeychain; | ||
| 145 | -} | ||
| 146 | - | ||
| 147 | - | ||
| 148 | -- (void)setDownloadDestinationPath:(NSString *)newDestinationPath | ||
| 149 | -{ | ||
| 150 | - [downloadDestinationPath release]; | ||
| 151 | - downloadDestinationPath = [newDestinationPath retain]; | ||
| 152 | -} | ||
| 153 | - | ||
| 154 | - | ||
| 155 | -- (NSString *)downloadDestinationPath | ||
| 156 | -{ | ||
| 157 | - return downloadDestinationPath; | ||
| 158 | -} | ||
| 159 | - | ||
| 160 | -- (void)setDidFinishSelector:(SEL)selector | ||
| 161 | -{ | ||
| 162 | - didFinishSelector = selector; | ||
| 163 | -} | ||
| 164 | - | ||
| 165 | -- (void)setDidFailSelector:(SEL)selector | ||
| 166 | -{ | ||
| 167 | - didFinishSelector = selector; | ||
| 168 | -} | ||
| 169 | - | ||
| 170 | - | ||
| 171 | 124 | ||
| 172 | 125 | ||
| 173 | #pragma mark get information about this request | 126 | #pragma mark get information about this request |
| 174 | 127 | ||
| 175 | -- (NSString *)authenticationRealm | ||
| 176 | -{ | ||
| 177 | - return authenticationRealm; | ||
| 178 | -} | ||
| 179 | - | ||
| 180 | -- (NSString *)host | ||
| 181 | -{ | ||
| 182 | - return [url host]; | ||
| 183 | -} | ||
| 184 | - | ||
| 185 | -- (NSError *)error | ||
| 186 | -{ | ||
| 187 | - return error; | ||
| 188 | -} | ||
| 189 | - | ||
| 190 | -- (void)setError:(NSError *)newError | ||
| 191 | -{ | ||
| 192 | - [error release]; | ||
| 193 | - error = [newError retain]; | ||
| 194 | -} | ||
| 195 | - | ||
| 196 | - | ||
| 197 | - | ||
| 198 | -- (BOOL)complete | ||
| 199 | -{ | ||
| 200 | - return complete; | ||
| 201 | -} | ||
| 202 | - | ||
| 203 | - (BOOL)isFinished | 128 | - (BOOL)isFinished |
| 204 | { | 129 | { |
| 205 | return complete; | 130 | return complete; |
| @@ -216,8 +141,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | @@ -216,8 +141,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | ||
| 216 | if (!receivedData) { | 141 | if (!receivedData) { |
| 217 | return nil; | 142 | return nil; |
| 218 | } | 143 | } |
| 219 | - NSString *theData = [[[NSString alloc] initWithBytes:[(NSData *)receivedData bytes] length:[(NSData *)receivedData length] encoding:NSUTF8StringEncoding] autorelease]; | 144 | + return [[[NSString alloc] initWithBytes:[(NSData *)receivedData bytes] length:[(NSData *)receivedData length] encoding:NSUTF8StringEncoding] autorelease]; |
| 220 | - return theData; | ||
| 221 | } | 145 | } |
| 222 | 146 | ||
| 223 | 147 | ||
| @@ -451,10 +375,10 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | @@ -451,10 +375,10 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | ||
| 451 | { | 375 | { |
| 452 | complete = YES; | 376 | complete = YES; |
| 453 | if (!error) { | 377 | if (!error) { |
| 454 | - error = [[NSError errorWithDomain:NetworkRequestErrorDomain | 378 | + [self setError:[NSError errorWithDomain:NetworkRequestErrorDomain |
| 455 | code:1 | 379 | code:1 |
| 456 | userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"An error occurred",@"Title", | 380 | userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"An error occurred",@"Title", |
| 457 | - problem,@"Description",nil]] retain]; | 381 | + problem,@"Description",nil]]]; |
| 458 | NSLog(problem); | 382 | NSLog(problem); |
| 459 | 383 | ||
| 460 | if (didFailSelector && ![self isCancelled] && [delegate respondsToSelector:didFailSelector]) { | 384 | if (didFailSelector && ![self isCancelled] && [delegate respondsToSelector:didFailSelector]) { |
| @@ -801,6 +725,16 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | @@ -801,6 +725,16 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy | ||
| 801 | 725 | ||
| 802 | } | 726 | } |
| 803 | 727 | ||
| 804 | - | 728 | +@synthesize url; |
| 729 | +@synthesize delegate; | ||
| 730 | +@synthesize uploadProgressDelegate; | ||
| 731 | +@synthesize downloadProgressDelegate; | ||
| 732 | +@synthesize usesKeychain; | ||
| 733 | +@synthesize downloadDestinationPath; | ||
| 734 | +@synthesize didFinishSelector; | ||
| 735 | +@synthesize didFailSelector; | ||
| 736 | +@synthesize authenticationRealm; | ||
| 737 | +@synthesize error; | ||
| 738 | +@synthesize complete; | ||
| 805 | 739 | ||
| 806 | @end | 740 | @end |
| @@ -131,7 +131,7 @@ | @@ -131,7 +131,7 @@ | ||
| 131 | - (void)authorizationNeededForRequest:(ASIHTTPRequest *)request | 131 | - (void)authorizationNeededForRequest:(ASIHTTPRequest *)request |
| 132 | { | 132 | { |
| 133 | [realm setStringValue:[request authenticationRealm]]; | 133 | [realm setStringValue:[request authenticationRealm]]; |
| 134 | - [host setStringValue:[request host]]; | 134 | + [host setStringValue:[[request url] host]]; |
| 135 | 135 | ||
| 136 | [NSApp beginSheet: loginWindow | 136 | [NSApp beginSheet: loginWindow |
| 137 | modalForWindow: window | 137 | modalForWindow: window |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment