Files
RestKit/Code/Support/NSDictionary+RKAdditions.m
Greg Combs 62d7042ebc Merge pull request #334 from parkerboundy/add-apache-license
Add the Apache License to headers (Issue #145) Closes #145.  Thanks @parkerboundy.
2011-09-14 21:56:15 -07:00

57 lines
1.9 KiB
Objective-C

//
// NSDictionary+RKAdditions.m
// RestKit
//
// Created by Blake Watters on 9/5/10.
// Copyright 2010 Two Toasters
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import "NSDictionary+RKAdditions.h"
#import "RKFixCategoryBug.h"
RK_FIX_CATEGORY_BUG(NSDictionary_RKAdditions)
@implementation NSDictionary (RKAdditions)
+ (id)dictionaryWithKeysAndObjects:(id)firstKey, ... {
va_list args;
va_start(args, firstKey);
NSMutableArray* keys = [NSMutableArray array];
NSMutableArray* values = [NSMutableArray array];
for (id key = firstKey; key != nil; key = va_arg(args, id)) {
id value = va_arg(args, id);
[keys addObject:key];
[values addObject:value];
}
va_end(args);
return [self dictionaryWithObjects:values forKeys:keys];
}
- (NSDictionary *)removePercentEscapesFromKeysAndObjects {
NSMutableDictionary *results = [NSMutableDictionary dictionaryWithCapacity:[self count]];
[self enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop)
{
NSString *escapedKey = [key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
id escapedValue = value;
if ([value respondsToSelector:@selector(stringByReplacingPercentEscapesUsingEncoding:)])
escapedValue = [value stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[results setObject:escapedValue forKey:escapedKey];
}];
return results;
}
@end