Created
July 29, 2012 07:51
-
-
Save tonyarnold/3196558 to your computer and use it in GitHub Desktop.
Add simple object subscripting to NSUserDefaults
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
// | |
// NSUserDefaults+ObjectSubscripting.h | |
// | |
// Created by Tony Arnold on 29/07/12. | |
// Copyright (c) 2012 The CocoaBots. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSUserDefaults (ObjectSubscripting) | |
- (id)objectForKeyedSubscript:(NSString *)key; | |
- (void)setObject:(id)object forKeyedSubscript:(NSString *)key; | |
@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
// | |
// NSUserDefaults+ObjectSubscripting.m | |
// | |
// Created by Tony Arnold on 29/07/12. | |
// Copyright (c) 2012 The CocoaBots. All rights reserved. | |
// | |
#import "NSUserDefaults+ObjectSubscripting.h" | |
@implementation NSUserDefaults (ObjectSubscripting) | |
- (id)objectForKeyedSubscript:(NSString *)key | |
{ | |
return [self objectForKey:key]; | |
} | |
- (void)setObject:(id)object forKeyedSubscript:(NSString *)key | |
{ | |
if (CBIsEmpty(object)) { | |
[self removeObjectForKey:key]; | |
} else { | |
[self setObject:object forKey:key]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ahh, sorry @casademora — there's a version of it here: https://gist.github.com/2010649
I'll post an updated version later on.