Created
July 29, 2012 00:36
-
-
Save joelparsons/3195445 to your computer and use it in GitHub Desktop.
Category on NSCoder to support the objective-c subscript syntax
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
// | |
// NSCoder+subscript.h | |
// | |
// Created by Joel Parsons on 29/07/2012. | |
// Copyright (c) 2012 All rights reserved. | |
// | |
//This category adds objective-c subscript support to NSCoder for basic object types | |
//handy for implementing NSCoding. | |
//without this category: | |
//[anEncoder encodeObject:object forKey:key]; | |
//object = [aDecoder objectForKey:key]; | |
//with this category: | |
//anEncoder[key] = object; | |
//object = aDecoder[key]; | |
#import <Foundation/Foundation.h> | |
@interface NSCoder (subscript) | |
- (id)objectForKeyedSubscript:(NSString *)key; | |
- (void)setObject:(id)object forKeyedSubscript:(NSString *)aKey; | |
@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
// | |
// NSCoder+subscript.m | |
// | |
// Created by Joel Parsons on 29/07/2012. | |
// Copyright (c) 2012 All rights reserved. | |
// | |
#import "NSCoder+subscript.h" | |
@implementation NSCoder (subscript) | |
-(id)objectForKeyedSubscript:(NSString *)key{ | |
return [self decodeObjectForKey:key]; | |
} | |
-(void)setObject:(id)object forKeyedSubscript:(NSString *)aKey{ | |
[self encodeObject:object forKey:aKey]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment