-
-
Save orj/5418430 to your computer and use it in GitHub Desktop.
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
-(void) encodeWithCoder: (NSCoder*) coder | |
{ | |
#define X(type, ivar) [coder encode##type:ivar forKey:@#ivar]; | |
#define BOX(type, ivar) [coder encodeObject:([NSValue valueWith##type:ivar]) forKey:@#ivar]; | |
XEncodeIvars | |
#undef BOX | |
#undef X | |
} | |
-(id) initWithCoder: (NSCoder*) decoder | |
{ | |
#define X(type, ivar) ivar = [decoder decode##type##ForKey:@#ivar]; | |
#define BOX(type, ivar) ivar = [[decoder decodeObjectForKey:@#ivar] type##Value]; | |
XEncodeIvars | |
#undef BOX | |
#undef X | |
return self; | |
} |
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
@interface Foo : NSObject <NSCoder> | |
@property BOOL aBool; | |
@property BOOL anotherBool; | |
@property NSInteger anInteger; | |
@property NSInteger anotherInteger; | |
@property NSObject * anObject; | |
@property NSObject * anotherObject; | |
@property CLLocationCoordinate2D location; | |
@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
@implementation Foo | |
#define XEncodeIvars \ | |
X(Bool, _aBool) \ | |
X(Bool, _anotherBool) \ | |
X(Integer, _anInteger) \ | |
X(Integer, _anotherInteger) \ | |
X(Object, _anObject) \ | |
X(Object, _anotherObject) \ | |
BOX(MKCoordinate, _location)) | |
#include "XSynthesizeCoders.h" | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment