From 84e953c24dcb2eee7e7e5760b555163486010df3 Mon Sep 17 00:00:00 2001 From: Suhas Joshi Date: Tue, 13 Mar 2012 21:34:09 -0700 Subject: [PATCH] Use [NSDictionary objectForKey:] instead of [NSDictionary valueForKey:] to access objects in dictionaries Summary: valueForKey also works in this case since none of our keys are strings staring with "@". However, objectForKey: is the correct selector to use for the desired behavior. Test Plan: Verify behavior with HackBook app Reviewers: jacl, dgibson Reviewed By: jacl Differential Revision: https://phabricator.fb.com/D427850 Task ID: 854847 --- src/FBRequest.m | 14 +++++++------- src/Facebook.m | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/FBRequest.m b/src/FBRequest.m index 0c65f546de..f12b89513d 100644 --- a/src/FBRequest.m +++ b/src/FBRequest.m @@ -85,8 +85,8 @@ + (NSString*)serializeURL:(NSString *)baseUrl NSMutableArray* pairs = [NSMutableArray array]; for (NSString* key in [params keyEnumerator]) { - if (([[params valueForKey:key] isKindOfClass:[UIImage class]]) - ||([[params valueForKey:key] isKindOfClass:[NSData class]])) { + if (([[params objectForKey:key] isKindOfClass:[UIImage class]]) + ||([[params objectForKey:key] isKindOfClass:[NSData class]])) { if ([httpMethod isEqualToString:@"GET"]) { NSLog(@"can not use GET to upload a file"); } @@ -127,10 +127,10 @@ - (NSMutableData *)generatePostBody { for (id key in [_params keyEnumerator]) { - if (([[_params valueForKey:key] isKindOfClass:[UIImage class]]) - ||([[_params valueForKey:key] isKindOfClass:[NSData class]])) { + if (([[_params objectForKey:key] isKindOfClass:[UIImage class]]) + ||([[_params objectForKey:key] isKindOfClass:[NSData class]])) { - [dataDictionary setObject:[_params valueForKey:key] forKey:key]; + [dataDictionary setObject:[_params objectForKey:key] forKey:key]; continue; } @@ -139,14 +139,14 @@ - (NSMutableData *)generatePostBody { data:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key]]; - [self utfAppendBody:body data:[_params valueForKey:key]]; + [self utfAppendBody:body data:[_params objectForKey:key]]; [self utfAppendBody:body data:endLine]; } if ([dataDictionary count] > 0) { for (id key in dataDictionary) { - NSObject *dataParam = [dataDictionary valueForKey:key]; + NSObject *dataParam = [dataDictionary objectForKey:key]; if ([dataParam isKindOfClass:[UIImage class]]) { NSData* imageData = UIImagePNGRepresentation((UIImage*)dataParam); [self utfAppendBody:body diff --git a/src/Facebook.m b/src/Facebook.m index 45499e44a4..b81a4e8bc9 100644 --- a/src/Facebook.m +++ b/src/Facebook.m @@ -415,11 +415,11 @@ - (BOOL)handleOpenURL:(NSURL *)url { } NSDictionary *params = [self parseURLParams:query]; - NSString *accessToken = [params valueForKey:@"access_token"]; + NSString *accessToken = [params objectForKey:@"access_token"]; // If the URL doesn't contain the access token, an error has occurred. if (!accessToken) { - NSString *errorReason = [params valueForKey:@"error"]; + NSString *errorReason = [params objectForKey:@"error"]; // If the error response indicates that we should try again using Safari, open // the authorization dialog in Safari. @@ -438,7 +438,7 @@ - (BOOL)handleOpenURL:(NSURL *)url { // The facebook app may return an error_code parameter in case it // encounters a UIWebViewDelegate error. This should not be treated // as a cancel. - NSString *errorCode = [params valueForKey:@"error_code"]; + NSString *errorCode = [params objectForKey:@"error_code"]; BOOL userDidCancel = !errorCode && (!errorReason || [errorReason isEqualToString:@"access_denied"]); @@ -447,7 +447,7 @@ - (BOOL)handleOpenURL:(NSURL *)url { } // We have an access token, so parse the expiration date. - NSString *expTime = [params valueForKey:@"expires_in"]; + NSString *expTime = [params objectForKey:@"expires_in"]; NSDate *expirationDate = [NSDate distantFuture]; if (expTime != nil) { int expVal = [expTime intValue];