Skip to content

Commit 90849d0

Browse files
committed
A bit of code modernization
1 parent 6af5059 commit 90849d0

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

RSOAuthEngine/RSOAuthEngine.m

+28-26
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,18 @@ - (id)initWithHostName:(NSString *)hostName
115115
_callbackURL = callbackURL;
116116
_signatureMethod = signatureMethod;
117117

118-
_oAuthValues = [NSMutableDictionary dictionaryWithObjectsAndKeys:
119-
oauthVersion, @"oauth_version",
120-
oauthSignatureMethodName[_signatureMethod], @"oauth_signature_method",
121-
consumerKey, @"oauth_consumer_key",
122-
@"", @"oauth_token",
123-
@"", @"oauth_verifier",
124-
@"", @"oauth_callback",
125-
@"", @"oauth_signature",
126-
@"", @"oauth_timestamp",
127-
@"", @"oauth_nonce",
128-
@"", @"realm",
129-
nil];
118+
_oAuthValues = [@{
119+
@"oauth_version": oauthVersion,
120+
@"oauth_signature_method": oauthSignatureMethodName[_signatureMethod],
121+
@"oauth_consumer_key": consumerKey,
122+
@"oauth_token": @"",
123+
@"oauth_verifier": @"",
124+
@"oauth_callback": @"",
125+
@"oauth_signature": @"",
126+
@"oauth_timestamp": @"",
127+
@"oauth_nonce": @"",
128+
@"realm": @""
129+
} mutableCopy];
130130

131131
[self resetOAuthToken];
132132

@@ -161,9 +161,12 @@ - (NSString *)signatureBaseStringForURL:(NSString *)url method:(NSString *)metho
161161
}
162162

163163
// Add parameters from the OAuth header
164-
[_oAuthValues enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
164+
[_oAuthValues enumerateKeysAndObjectsUsingBlock:^(id key, NSString *obj, BOOL *stop) {
165165
if ([key hasPrefix:@"oauth_"] && ![key isEqualToString:@"oauth_signature"] && obj && ![obj isEqualToString:@""]) {
166-
[parameters addObject:[NSDictionary dictionaryWithObjectsAndKeys:[key mk_urlEncodedString], @"key", [obj mk_urlEncodedString], @"value", nil]];
166+
[parameters addObject:@{
167+
@"key": [key mk_urlEncodedString],
168+
@"value": [obj mk_urlEncodedString]
169+
}];
167170
}
168171
}];
169172

@@ -177,7 +180,7 @@ - (NSString *)signatureBaseStringForURL:(NSString *)url method:(NSString *)metho
177180

178181
// Join sorted components
179182
NSMutableArray *normalizedParameters = [NSMutableArray array];
180-
[parameters enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
183+
[parameters enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
181184
[normalizedParameters addObject:[NSString stringWithFormat:@"%@=%@", [obj objectForKey:@"key"], [obj objectForKey:@"value"]]];
182185
}];
183186

@@ -203,12 +206,12 @@ - (NSString *)signatureBaseStringForRequest:(MKNetworkOperation *)request
203206
if ([request.filesToBePosted count] == 0 && [request.dataToBePosted count] == 0) {
204207
// Add parameters from the query string
205208
NSArray *pairs = [url.query componentsSeparatedByString:@"&"];
206-
[pairs enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
209+
[pairs enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
207210
NSArray *elements = [obj componentsSeparatedByString:@"="];
208211
NSString *key = [elements objectAtIndex:0];
209212
NSString *value = (elements.count > 1) ? [elements objectAtIndex:1] : @"";
210213

211-
[parameters addObject:[NSDictionary dictionaryWithObjectsAndKeys:key, @"key", value, @"value", nil]];
214+
[parameters addObject:@{@"key": key, @"value": value}];
212215
}];
213216

214217
// Add parameters from the request body
@@ -308,9 +311,8 @@ - (void)fillTokenWithResponseBody:(NSString *)body type:(RSOAuthTokenType)tokenT
308311
{
309312
NSArray *pairs = [body componentsSeparatedByString:@"&"];
310313

311-
for (NSString *pair in pairs)
312-
{
313-
NSArray *elements = [pair componentsSeparatedByString:@"="];
314+
[pairs enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
315+
NSArray *elements = [obj componentsSeparatedByString:@"="];
314316
NSString *key = [[elements objectAtIndex:0] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
315317
NSString *value = [[elements objectAtIndex:1] urlDecodedString];
316318

@@ -323,7 +325,7 @@ - (void)fillTokenWithResponseBody:(NSString *)body type:(RSOAuthTokenType)tokenT
323325
} else {
324326
[self addCustomValue:value withKey:key];
325327
}
326-
}
328+
}];
327329

328330
_tokenType = tokenType;
329331

@@ -377,19 +379,19 @@ - (void)signRequest:(MKNetworkOperation *)request
377379
if (self.parameterStyle == RSOAuthParameterStyleHeader) {
378380
NSMutableArray *oauthHeaders = [NSMutableArray array];
379381

380-
[_oAuthValues enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
382+
[_oAuthValues enumerateKeysAndObjectsUsingBlock:^(id key, NSString *obj, BOOL *stop) {
381383
if (obj && ![obj isEqualToString:@""]) {
382384
[oauthHeaders addObject:[NSString stringWithFormat:@"%@=\"%@\"", [key mk_urlEncodedString], [obj mk_urlEncodedString]]];
383385
}
384386
}];
385387

386388
// Set the Authorization header
387389
NSString *oauthData = [NSString stringWithFormat:@"OAuth %@", [oauthHeaders componentsJoinedByString:@", "]];
388-
NSDictionary *oauthHeader = [NSDictionary dictionaryWithObjectsAndKeys:oauthData, @"Authorization", nil];
390+
NSDictionary *oauthHeader = @{@"Authorization": oauthData};
389391

390392
[request addHeaders:oauthHeader];
391393
} else if (self.parameterStyle == RSOAuthParameterStylePostBody && [request.readonlyRequest.HTTPMethod caseInsensitiveCompare:@"GET"] != NSOrderedSame) {
392-
[_oAuthValues enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
394+
[_oAuthValues enumerateKeysAndObjectsUsingBlock:^(id key, NSString *obj, BOOL *stop) {
393395
if (obj && ![obj isEqualToString:@""]) {
394396
[request rs_setValue:obj forKey:key];
395397
}
@@ -398,7 +400,7 @@ - (void)signRequest:(MKNetworkOperation *)request
398400
NSMutableArray *oauthParams = [NSMutableArray array];
399401

400402
// Fill the authorization header array
401-
[_oAuthValues enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
403+
[_oAuthValues enumerateKeysAndObjectsUsingBlock:^(id key, NSString *obj, BOOL *stop) {
402404
if (obj && ![obj isEqualToString:@""]) {
403405
[oauthParams addObject:[NSString stringWithFormat:@"%@=%@", [key mk_urlEncodedString], [obj mk_urlEncodedString]]];
404406
}
@@ -442,7 +444,7 @@ - (NSString *)generateXOAuthStringForURL:(NSString *)url method:(NSString *)meth
442444
NSMutableArray *oauthHeaders = [NSMutableArray array];
443445

444446
// Fill the authorization header array
445-
[_oAuthValues enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
447+
[_oAuthValues enumerateKeysAndObjectsUsingBlock:^(id key, NSString *obj, BOOL *stop) {
446448
if (obj && ![obj isEqualToString:@""]) {
447449
[oauthHeaders addObject:[NSString stringWithFormat:@"%@=\"%@\"", [key mk_urlEncodedString], [obj mk_urlEncodedString]]];
448450
}

TwitterDemo.xcodeproj/project.pbxproj

+11-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
5B9770BA149789C200791728 /* Project object */ = {
244244
isa = PBXProject;
245245
attributes = {
246-
LastUpgradeCheck = 0420;
246+
LastUpgradeCheck = 0460;
247247
ORGANIZATIONNAME = SharpCube;
248248
};
249249
buildConfigurationList = 5B9770BD149789C200791728 /* Build configuration list for PBXProject "TwitterDemo" */;
@@ -336,6 +336,10 @@
336336
ALWAYS_SEARCH_USER_PATHS = NO;
337337
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
338338
CLANG_ENABLE_OBJC_ARC = YES;
339+
CLANG_WARN_CONSTANT_CONVERSION = YES;
340+
CLANG_WARN_ENUM_CONVERSION = YES;
341+
CLANG_WARN_INT_CONVERSION = YES;
342+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
339343
CODE_SIGN_IDENTITY = "iPhone Developer";
340344
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
341345
COPY_PHASE_STRIP = NO;
@@ -350,6 +354,7 @@
350354
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
351355
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
352356
GCC_WARN_ABOUT_RETURN_TYPE = YES;
357+
GCC_WARN_UNINITIALIZED_AUTOS = YES;
353358
GCC_WARN_UNUSED_VARIABLE = YES;
354359
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
355360
PROVISIONING_PROFILE = "";
@@ -364,13 +369,18 @@
364369
ALWAYS_SEARCH_USER_PATHS = NO;
365370
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
366371
CLANG_ENABLE_OBJC_ARC = YES;
372+
CLANG_WARN_CONSTANT_CONVERSION = YES;
373+
CLANG_WARN_ENUM_CONVERSION = YES;
374+
CLANG_WARN_INT_CONVERSION = YES;
375+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
367376
CODE_SIGN_IDENTITY = "iPhone Developer";
368377
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
369378
COPY_PHASE_STRIP = YES;
370379
GCC_C_LANGUAGE_STANDARD = gnu99;
371380
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
372381
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
373382
GCC_WARN_ABOUT_RETURN_TYPE = YES;
383+
GCC_WARN_UNINITIALIZED_AUTOS = YES;
374384
GCC_WARN_UNUSED_VARIABLE = YES;
375385
IPHONEOS_DEPLOYMENT_TARGET = 4.3;
376386
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";

0 commit comments

Comments
 (0)