diff --git a/MGTwitterEngine.h b/MGTwitterEngine.h index 3a11e62..e92494a 100644 --- a/MGTwitterEngine.h +++ b/MGTwitterEngine.h @@ -11,12 +11,11 @@ #import "MGTwitterEngineDelegate.h" #import "MGTwitterParserDelegate.h" -#import "OAToken.h" - +@class OAToken; @interface MGTwitterEngine : NSObject { - __weak NSObject *_delegate; + __unsafe_unretained NSObject *_delegate; NSMutableDictionary *_connections; // MGTwitterHTTPURLConnection objects NSString *_clientName; NSString *_clientVersion; diff --git a/MGTwitterEngine.m b/MGTwitterEngine.m index dc1841c..b99cf4d 100644 --- a/MGTwitterEngine.m +++ b/MGTwitterEngine.m @@ -8,7 +8,7 @@ #import "MGTwitterEngine.h" #import "MGTwitterHTTPURLConnection.h" -#import "OAuthConsumer.h" +#import #import "NSData+Base64.h" @@ -79,9 +79,9 @@ @implementation NSDictionary (MGTwitterEngineExtensions) -(NSDictionary *)MGTE_dictionaryByRemovingObjectForKey:(NSString *)key{ NSDictionary *result = self; if(key){ - NSMutableDictionary *newParams = [[self mutableCopy] autorelease]; + NSMutableDictionary *newParams = [self mutableCopy]; [newParams removeObjectForKey:key]; - result = [[newParams copy] autorelease]; + result = [newParams copy]; } return result; } @@ -139,7 +139,7 @@ @implementation MGTwitterEngine + (MGTwitterEngine *)twitterEngineWithDelegate:(NSObject *)theDelegate { - return [[[self alloc] initWithDelegate:theDelegate] autorelease]; + return [[self alloc] initWithDelegate:theDelegate]; } @@ -148,11 +148,11 @@ - (MGTwitterEngine *)initWithDelegate:(NSObject *)newDelegate if ((self = [super init])) { _delegate = newDelegate; // deliberately weak reference _connections = [[NSMutableDictionary alloc] initWithCapacity:0]; - _clientName = [DEFAULT_CLIENT_NAME retain]; - _clientVersion = [DEFAULT_CLIENT_VERSION retain]; - _clientURL = [DEFAULT_CLIENT_URL retain]; - _clientSourceToken = [DEFAULT_CLIENT_TOKEN retain]; - _APIDomain = [TWITTER_DOMAIN retain]; + _clientName = DEFAULT_CLIENT_NAME; + _clientVersion = DEFAULT_CLIENT_VERSION; + _clientURL = DEFAULT_CLIENT_URL; + _clientSourceToken = DEFAULT_CLIENT_TOKEN; + _APIDomain = TWITTER_DOMAIN; #if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE _searchDomain = [TWITTER_SEARCH_DOMAIN retain]; #endif @@ -173,20 +173,10 @@ - (void)dealloc _delegate = nil; [[_connections allValues] makeObjectsPerformSelector:@selector(cancel)]; - [_connections release]; - - [_username release]; - [_password release]; - [_clientName release]; - [_clientVersion release]; - [_clientURL release]; - [_clientSourceToken release]; - [_APIDomain release]; + #if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE [_searchDomain release]; #endif - - [super dealloc]; } @@ -209,54 +199,49 @@ + (NSString *)version - (NSString *)clientName { - return [[_clientName retain] autorelease]; + return _clientName; } - (NSString *)clientVersion { - return [[_clientVersion retain] autorelease]; + return _clientVersion; } - (NSString *)clientURL { - return [[_clientURL retain] autorelease]; + return _clientURL; } - (NSString *)clientSourceToken { - return [[_clientSourceToken retain] autorelease]; + return _clientSourceToken; } - (void)setClientName:(NSString *)name version:(NSString *)version URL:(NSString *)url token:(NSString *)token; { - [_clientName release]; - _clientName = [name retain]; - [_clientVersion release]; - _clientVersion = [version retain]; - [_clientURL release]; - _clientURL = [url retain]; - [_clientSourceToken release]; - _clientSourceToken = [token retain]; + _clientName = name; + _clientVersion = version; + _clientURL = url; + _clientSourceToken = token; } - (NSString *)APIDomain { - return [[_APIDomain retain] autorelease]; + return _APIDomain; } - (void)setAPIDomain:(NSString *)domain { - [_APIDomain release]; if (!domain || [domain length] == 0) { - _APIDomain = [TWITTER_DOMAIN retain]; + _APIDomain = TWITTER_DOMAIN; } else { - _APIDomain = [domain retain]; + _APIDomain = domain; } } @@ -360,7 +345,7 @@ - (NSDateFormatter *)_HTTPDateFormatter { // Returns a formatter for dates in HTTP format (i.e. RFC 822, updated by RFC 1123). // e.g. "Sun, 06 Nov 1994 08:49:37 GMT" - NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; + NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; //[dateFormatter setDateFormat:@"%a, %d %b %Y %H:%M:%S GMT"]; // won't work with -init, which uses new (unicode) format behaviour. [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; [dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss GMT"]; @@ -412,12 +397,12 @@ - (NSString *)_dateToHTTP:(NSDate *)date - (NSString *)_encodeString:(NSString *)string { - NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, - (CFStringRef)string, + NSString *result = (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, + (__bridge CFStringRef)string, NULL, (CFStringRef)@";/?:@&=$+{}<>,", kCFStringEncodingUTF8); - return [result autorelease]; + return result; } @@ -448,7 +433,6 @@ - (NSString *)getImageAtURL:(NSString *)urlString return nil; } else { [_connections setObject:connection forKey:[connection identifier]]; - [connection release]; } if ([self _isValidDelegateForSelector:@selector(connectionStarted:)]) @@ -519,7 +503,6 @@ -(NSString*)_sendRequest:(NSURLRequest *)theRequest withRequestType:(MGTwitterRe return nil; } else { [_connections setObject:connection forKey:[connection identifier]]; - [connection release]; } if ([self _isValidDelegateForSelector:@selector(connectionStarted:)]) @@ -581,7 +564,6 @@ - (NSString *)_sendDataRequestWithMethod:(NSString *)method return nil; } else { [_connections setObject:connection forKey:[connection identifier]]; - [connection release]; } if ([self _isValidDelegateForSelector:@selector(connectionStarted:)]) @@ -668,12 +650,12 @@ - (NSMutableURLRequest *)_baseRequestWithMethod:(NSString *)method // Construct an NSMutableURLRequest for the URL and set appropriate request method. NSMutableURLRequest *theRequest = nil; if(_accessToken){ - theRequest = [[[OAMutableURLRequest alloc] initWithURL:finalURL - consumer:[[[OAConsumer alloc] initWithKey:[self consumerKey] - secret:[self consumerSecret]] autorelease] + theRequest = [[OAMutableURLRequest alloc] initWithURL:finalURL + consumer:[[OAConsumer alloc] initWithKey:[self consumerKey] + secret:[self consumerSecret]] token:_accessToken realm:nil - signatureProvider:nil] autorelease]; + signatureProvider:nil]; [theRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData ]; [theRequest setTimeoutInterval:URL_REQUEST_TIMEOUT]; }else{ @@ -782,8 +764,8 @@ - (void)_parseDataForConnection:(MGTwitterHTTPURLConnection *)connection #else - (void)_parseDataForConnection:(MGTwitterHTTPURLConnection *)connection { - NSString *identifier = [[[connection identifier] copy] autorelease]; - NSData *xmlData = [[[connection data] copy] autorelease]; + NSString *identifier = [[connection identifier] copy]; + NSData *xmlData = [[connection data] copy]; MGTwitterRequestType requestType = [connection requestType]; MGTwitterResponseType responseType = [connection responseType]; @@ -863,10 +845,12 @@ - (void)_parseDataForConnection:(MGTwitterHTTPURLConnection *)connection [MGTwitterSocialGraphParser parserWithXML:xmlData delegate:self connectionIdentifier:identifier requestType:requestType responseType:responseType]; - case MGTwitterOAuthToken:; - OAToken *token = [[[OAToken alloc] initWithHTTPResponseBody:[[[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding] autorelease]] autorelease]; + case MGTwitterOAuthToken: + { + OAToken *token = [[OAToken alloc] initWithHTTPResponseBody:[[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding]]; [self parsingSucceededForRequest:identifier ofResponseType:requestType withParsedObjects:[NSArray arrayWithObject:token]]; + } default: break; } @@ -1092,7 +1076,7 @@ - (void)connectionDidFinishLoading:(MGTwitterHTTPURLConnection *)connection #if TARGET_OS_IPHONE UIImage *image = [[[UIImage alloc] initWithData:[connection data]] autorelease]; #else - NSImage *image = [[[NSImage alloc] initWithData:[connection data]] autorelease]; + NSImage *image = [[NSImage alloc] initWithData:[connection data]]; #endif // Inform delegate. @@ -2053,29 +2037,26 @@ @implementation MGTwitterEngine (BasicAuth) - (NSString *)username { - return [[_username retain] autorelease]; + return _username; } - (void)setUsername:(NSString *)newUsername { // Set new credentials. - [_username release]; - _username = [newUsername retain]; + _username = newUsername; } - (NSString *)password { - return [[_password retain] autorelease]; + return _password; } - (void)setUsername:(NSString *)newUsername password:(NSString *)newPassword { // Set new credentials. - [_username release]; - _username = [newUsername retain]; - [_password release]; - _password = [newPassword retain]; + _username = newUsername; + _password = newPassword; if ([self clearsCookies]) { // Remove all cookies for twitter, to ensure next connection uses new credentials. @@ -2098,10 +2079,8 @@ - (void)setUsername:(NSString *)newUsername password:(NSString *)newPassword @implementation MGTwitterEngine (OAuth) - (void)setConsumerKey:(NSString *)key secret:(NSString *)secret{ - [_consumerKey autorelease]; _consumerKey = [key copy]; - [_consumerSecret autorelease]; _consumerSecret = [secret copy]; } @@ -2114,8 +2093,7 @@ - (NSString *)consumerSecret{ } - (void)setAccessToken: (OAToken *)token{ - [_accessToken autorelease]; - _accessToken = [token retain]; + _accessToken = token; } - (OAToken *)accessToken{ @@ -2124,7 +2102,7 @@ - (OAToken *)accessToken{ - (NSString *)getXAuthAccessTokenForUsername:(NSString *)username password:(NSString *)password{ - OAConsumer *consumer = [[[OAConsumer alloc] initWithKey:[self consumerKey] secret:[self consumerSecret]] autorelease]; + OAConsumer *consumer = [[OAConsumer alloc] initWithKey:[self consumerKey] secret:[self consumerSecret]]; OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"] consumer:consumer @@ -2135,9 +2113,9 @@ - (NSString *)getXAuthAccessTokenForUsername:(NSString *)username [request setHTTPMethod:@"POST"]; [request setParameters:[NSArray arrayWithObjects: - [OARequestParameter requestParameter:@"x_auth_mode" value:@"client_auth"], - [OARequestParameter requestParameter:@"x_auth_username" value:username], - [OARequestParameter requestParameter:@"x_auth_password" value:password], + [OARequestParameter requestParameterWithName:@"x_auth_mode" value:@"client_auth"], + [OARequestParameter requestParameterWithName:@"x_auth_username" value:username], + [OARequestParameter requestParameterWithName:@"x_auth_password" value:password], nil]]; // Create a connection using this request, with the default timeout and caching policy, @@ -2148,13 +2126,12 @@ - (NSString *)getXAuthAccessTokenForUsername:(NSString *)username requestType:MGTwitterOAuthTokenRequest responseType:MGTwitterOAuthToken]; - [request release], request = nil; + request = nil; if (!connection) { return nil; } else { [_connections setObject:connection forKey:[connection identifier]]; - [connection release]; } if ([self _isValidDelegateForSelector:@selector(connectionStarted:)]) diff --git a/MGTwitterEngine.xcodeproj/project.pbxproj b/MGTwitterEngine.xcodeproj/project.pbxproj index 5d08506..6a5e8c8 100644 --- a/MGTwitterEngine.xcodeproj/project.pbxproj +++ b/MGTwitterEngine.xcodeproj/project.pbxproj @@ -582,7 +582,11 @@ isa = PBXProject; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "MGTwitterEngine" */; compatibilityVersion = "Xcode 3.0"; + developmentRegion = English; hasScannedForEncodings = 1; + knownRegions = ( + en, + ); mainGroup = 29B97314FDCFA39411CA2CEA /* MATwitterIntegration */; projectDirPath = ""; projectRoot = ""; @@ -716,8 +720,9 @@ "\"$(SRCROOT)/yajl/build/yajl-1.0.7/lib\"", "\"$(SRCROOT)\"", ); - ONLY_ACTIVE_ARCH_PRE_XCODE_3_1 = "$(NATIVE_ARCH_ACTUAL)"; + ONLY_ACTIVE_ARCH_PRE_XCODE_3_1 = "$(NATIVE_ARCH_64)"; PRODUCT_NAME = MGTwitterEngine; + SDKROOT = macosx; WRAPPER_EXTENSION = app; ZERO_LINK = YES; }; @@ -742,6 +747,7 @@ "\"$(SRCROOT)\"", ); PRODUCT_NAME = MGTwitterEngine; + SDKROOT = macosx; WRAPPER_EXTENSION = app; }; name = Release; diff --git a/MGTwitterHTTPURLConnection.m b/MGTwitterHTTPURLConnection.m index a43e906..ca51f6b 100644 --- a/MGTwitterHTTPURLConnection.m +++ b/MGTwitterHTTPURLConnection.m @@ -41,26 +41,15 @@ - (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate if ((self = [super initWithRequest:request delegate:delegate])) { _data = [[NSMutableData alloc] initWithCapacity:0]; - _identifier = [[NSString stringWithNewUUID] retain]; + _identifier = [NSString stringWithNewUUID]; _requestType = requestType; _responseType = responseType; - _URL = [[request URL] retain]; + _URL = [request URL]; } return self; } - -- (void)dealloc -{ - [_response release]; - [_data release]; - [_identifier release]; - [_URL release]; - [super dealloc]; -} - - #pragma mark Data helper methods @@ -81,19 +70,19 @@ - (void)appendData:(NSData *)data - (NSString *)identifier { - return [[_identifier retain] autorelease]; + return _identifier; } - (NSData *)data { - return [[_data retain] autorelease]; + return _data; } - (NSURL *)URL { - return [[_URL retain] autorelease]; + return _URL; } diff --git a/MGTwitterXMLParser.h b/MGTwitterXMLParser.h index 67ea357..4c19440 100644 --- a/MGTwitterXMLParser.h +++ b/MGTwitterXMLParser.h @@ -10,14 +10,14 @@ #import "MGTwitterParserDelegate.h" @interface MGTwitterXMLParser : NSObject { - __weak NSObject *delegate; // weak ref + __unsafe_unretained NSObject *delegate; // weak ref NSString *identifier; MGTwitterRequestType requestType; MGTwitterResponseType responseType; NSData *xml; NSMutableArray *parsedObjects; NSXMLParser *parser; - __weak NSMutableDictionary *currentNode; + __unsafe_unretained NSMutableDictionary *currentNode; NSString *lastOpenedElement; } diff --git a/MGTwitterXMLParser.m b/MGTwitterXMLParser.m index 2867143..aec689a 100644 --- a/MGTwitterXMLParser.m +++ b/MGTwitterXMLParser.m @@ -24,7 +24,7 @@ + (id)parserWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate connectionIdentifier:identifier requestType:reqType responseType:respType]; - return [parser autorelease]; + return parser; } @@ -33,8 +33,8 @@ - (id)initWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate responseType:(MGTwitterResponseType)respType { if ((self = [super init])) { - xml = [theXML retain]; - identifier = [theIdentifier retain]; + xml = theXML; + identifier = theIdentifier; requestType = reqType; responseType = respType; delegate = theDelegate; @@ -54,18 +54,6 @@ - (id)initWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate return self; } - -- (void)dealloc -{ - [parser release]; - [parsedObjects release]; - [xml release]; - [identifier release]; - delegate = nil; - [super dealloc]; -} - - #pragma mark NSXMLParser delegate methods @@ -116,8 +104,7 @@ - (void)parser:(NSXMLParser *)theParser didEndElement:(NSString *)elementName [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; dateFormatter.dateFormat = @"EEE MMM dd HH:mm:ss +0000 yyyy"; NSDate *creationDate = [dateFormatter dateFromString:[currentNode objectForKey:elementName]]; - [dateFormatter release]; - if (creationDate) { + if (creationDate) { [currentNode setObject:creationDate forKey:elementName]; } } @@ -149,13 +136,12 @@ - (void)parser:(NSXMLParser *)theParser parseErrorOccurred:(NSError *)parseError - (NSString *)lastOpenedElement { - return [[lastOpenedElement retain] autorelease]; + return lastOpenedElement; } - (void)setLastOpenedElement:(NSString *)value { if (lastOpenedElement != value) { - [lastOpenedElement release]; lastOpenedElement = [value copy]; } } diff --git a/NSData+Base64.m b/NSData+Base64.m index fb94a46..d188faa 100644 --- a/NSData+Base64.m +++ b/NSData+Base64.m @@ -22,7 +22,7 @@ @implementation NSData (Base64) + (NSData *) dataWithBase64EncodedString:(NSString *) string { NSData *result = [[NSData alloc] initWithBase64EncodedString:string]; - return [result autorelease]; + return result; } - (id) initWithBase64EncodedString:(NSString *) string { diff --git a/NSString+UUID.m b/NSString+UUID.m index e4a3ee3..2345c29 100644 --- a/NSString+UUID.m +++ b/NSString+UUID.m @@ -18,9 +18,9 @@ + (NSString*)stringWithNewUUID CFUUIDRef uuidObj = CFUUIDCreate(nil); // Get the string representation of the UUID - NSString *newUUID = (NSString*)CFUUIDCreateString(nil, uuidObj); + NSString *newUUID = (__bridge_transfer NSString*)CFUUIDCreateString(nil, uuidObj); CFRelease(uuidObj); - return [newUUID autorelease]; + return newUUID; }