Last active
August 29, 2015 14:12
-
-
Save mihyaeru21/cf3d928b15812e23a9c1 to your computer and use it in GitHub Desktop.
キーを変換しつつ新しいNSDictionaryを返すやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface NSDictionary (MBUtil) | |
- (instancetype)initWithDictionary:(NSDictionary *)dictionary withKeyDictionary:(NSDictionary *)keyDictionary; | |
+ (instancetype)dictionaryWithDictionary:(NSDictionary *)dictionary withKeyDictionary:(NSDictionary *)keyDictionary; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSDictionary+MBUtil.h" | |
@implementation NSDictionary (MBUtil) | |
- (instancetype)initWithDictionary:(NSDictionary *)dictionary withKeyDictionary:(NSDictionary *)keyDictionary | |
{ | |
__block NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionaryWithCapacity:dictionary.count]; | |
[keyDictionary enumerateKeysAndObjectsUsingBlock:^(id oldKey, id newKey, BOOL *stop) { | |
mutableDictionary[newKey] = dictionary[oldKey]; | |
}]; | |
return [self initWithDictionary:mutableDictionary]; | |
} | |
+ (instancetype)dictionaryWithDictionary:(NSDictionary *)dictionary withKeyDictionary:(NSDictionary *)keyDictionary | |
{ | |
return [[self alloc] initWithDictionary:dictionary withKeyDictionary:keyDictionary]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment