Ben Copsey

Convert getters / setters to obj-c 2.0 properties

Stop retaining delegate
... ... @@ -109,14 +109,6 @@
#pragma mark delegate configuration
// Delegate will get messages when the request completes, fails or when authentication is required
- (void)setDelegate:(id)newDelegate;
// upload progress delegate (usually an NSProgressIndicator) is sent information on upload progress
- (void)setUploadProgressDelegate:(id)newDelegate;
// download progress delegate (usually an NSProgressIndicator) is sent information on download progress
- (void)setDownloadProgressDelegate:(id)newDelegate;
#pragma mark setup request
... ... @@ -132,32 +124,8 @@
// When set, username and password will be presented for HTTP authentication
- (void)setUsername:(NSString *)newUsername andPassword:(NSString *)newPassword;
// When true, authentication information will automatically be stored in (and re-used from) the keychain
- (void)setUsesKeychain:(BOOL)shouldUseKeychain;
//the results of this request will be saved to downloadDestinationPath, if it is set
- (void)setDownloadDestinationPath:(NSString *)newDestinationPath;
- (NSString *)downloadDestinationPath;
// This selector will be called on the delegate when the request completes successfully
- (void)setDidFinishSelector:(SEL)selector;
// This selector will be called on the delegate when the request fails
- (void)setDidFailSelector:(SEL)selector;
#pragma mark get information about this request
// Accessors for getting information about the request (useful for auth dialogs)
- (NSString *)authenticationRealm;
- (NSString *)host;
// Contains a description of the error that occurred if the request failed
- (NSError *)error;
- (void)setError:(NSError *)newError;
// Will be true when the request is complete (success or failure)
- (BOOL)complete;
- (BOOL)isFinished; //Same thing, for NSOperationQueues to read
// Get total amount of data received so far for this request
... ... @@ -230,12 +198,17 @@
+ (void)removeCredentialsForHost:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm;
@property (retain,readonly) NSURL *url;
@property (assign) id delegate;
@property (assign) NSObject *uploadProgressDelegate;
@property (assign) NSObject *downloadProgressDelegate;
@property (assign) BOOL usesKeychain;
@property (retain) NSString *downloadDestinationPath;
@property (assign) SEL didFinishSelector;
@property (assign) SEL didFailSelector;
@property (retain,readonly) NSString *authenticationRealm;
@property (retain) NSError *error;
@property (assign,readonly) BOOL complete;
@end
... ...
... ... @@ -25,8 +25,12 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy
}
@implementation ASIHTTPRequest
#pragma mark init / dealloc
- (id)initWithURL:(NSURL *)newURL
... ... @@ -51,6 +55,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy
usesKeychain = NO;
didFinishSelector = @selector(requestFinished:);
didFailSelector = @selector(requestFailed:);
delegate = nil;
return self;
}
... ... @@ -67,9 +72,6 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy
}
[self cancelLoad];
[error release];
[delegate release];
[uploadProgressDelegate release];
[downloadProgressDelegate release];
[postData release];
[fileData release];
[requestHeaders release];
... ... @@ -83,26 +85,6 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy
[super dealloc];
}
#pragma mark delegate configuration
- (void)setDelegate:(id)newDelegate
{
[delegate release];
delegate = [newDelegate retain];
}
- (void)setUploadProgressDelegate:(id)newDelegate
{
[uploadProgressDelegate release];
uploadProgressDelegate = [newDelegate retain];
}
- (void)setDownloadProgressDelegate:(id)newDelegate
{
[downloadProgressDelegate release];
downloadProgressDelegate = [newDelegate retain];
}
#pragma mark setup request
... ... @@ -139,67 +121,10 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy
password = [newPassword retain];
}
- (void)setUsesKeychain:(BOOL)shouldUseKeychain
{
usesKeychain = shouldUseKeychain;
}
- (void)setDownloadDestinationPath:(NSString *)newDestinationPath
{
[downloadDestinationPath release];
downloadDestinationPath = [newDestinationPath retain];
}
- (NSString *)downloadDestinationPath
{
return downloadDestinationPath;
}
- (void)setDidFinishSelector:(SEL)selector
{
didFinishSelector = selector;
}
- (void)setDidFailSelector:(SEL)selector
{
didFinishSelector = selector;
}
#pragma mark get information about this request
- (NSString *)authenticationRealm
{
return authenticationRealm;
}
- (NSString *)host
{
return [url host];
}
- (NSError *)error
{
return error;
}
- (void)setError:(NSError *)newError
{
[error release];
error = [newError retain];
}
- (BOOL)complete
{
return complete;
}
- (BOOL)isFinished
{
return complete;
... ... @@ -216,8 +141,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy
if (!receivedData) {
return nil;
}
NSString *theData = [[[NSString alloc] initWithBytes:[(NSData *)receivedData bytes] length:[(NSData *)receivedData length] encoding:NSUTF8StringEncoding] autorelease];
return theData;
return [[[NSString alloc] initWithBytes:[(NSData *)receivedData bytes] length:[(NSData *)receivedData length] encoding:NSUTF8StringEncoding] autorelease];
}
... ... @@ -451,10 +375,10 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy
{
complete = YES;
if (!error) {
error = [[NSError errorWithDomain:NetworkRequestErrorDomain
[self setError:[NSError errorWithDomain:NetworkRequestErrorDomain
code:1
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"An error occurred",@"Title",
problem,@"Description",nil]] retain];
problem,@"Description",nil]]];
NSLog(problem);
if (didFailSelector && ![self isCancelled] && [delegate respondsToSelector:didFailSelector]) {
... ... @@ -801,6 +725,16 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy
}
@synthesize url;
@synthesize delegate;
@synthesize uploadProgressDelegate;
@synthesize downloadProgressDelegate;
@synthesize usesKeychain;
@synthesize downloadDestinationPath;
@synthesize didFinishSelector;
@synthesize didFailSelector;
@synthesize authenticationRealm;
@synthesize error;
@synthesize complete;
@end
... ...
... ... @@ -131,7 +131,7 @@
- (void)authorizationNeededForRequest:(ASIHTTPRequest *)request
{
[realm setStringValue:[request authenticationRealm]];
[host setStringValue:[request host]];
[host setStringValue:[[request url] host]];
[NSApp beginSheet: loginWindow
modalForWindow: window
... ...
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.