Last active
December 22, 2015 03:58
-
-
Save mattrajca/6413935 to your computer and use it in GitHub Desktop.
Category which adds keyed subscripting to NSUserDefaults
This file contains hidden or 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
// | |
// NSUserDefaults+Subscripting.h | |
// | |
// Created by Matt on 9/2/13. | |
// Copyright (c) 2013 Matt Rajca. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
/* keys must be NSStrings */ | |
@interface NSUserDefaults (Subscripting) | |
- (id)objectForKeyedSubscript:(id <NSCopying>)key; | |
- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key; | |
@end |
This file contains hidden or 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
// | |
// NSUserDefaults+Subscripting.m | |
// | |
// Created by Matt on 9/2/13. | |
// Copyright (c) 2013 Matt Rajca. All rights reserved. | |
// | |
#import "NSUserDefaults+Subscripting.h" | |
@implementation NSUserDefaults (Subscripting) | |
- (id)objectForKeyedSubscript:(id <NSCopying>)key { | |
if (![(NSObject *)key isKindOfClass:[NSString class]]) | |
return nil; | |
return [self objectForKey:(NSString *)key]; | |
} | |
- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key { | |
if (![(NSObject *)key isKindOfClass:[NSString class]]) | |
return; | |
[self setObject:obj forKey:(NSString *)key]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment