Skip to content

Instantly share code, notes, and snippets.

@orj
Forked from aufflick/XSynthesizeCoders.h
Last active December 16, 2015 10:09
Show Gist options
  • Select an option

  • Save orj/5418430 to your computer and use it in GitHub Desktop.

Select an option

Save orj/5418430 to your computer and use it in GitHub Desktop.
-(void) encodeWithCoder: (NSCoder*) coder
{
#define X(ivar) [coder encodeBool:ivar forKey:@"" #ivar];
XEncodeBools
#undef X
#define X(ivar) [coder encodeInteger:ivar forKey:@"" #ivar];
XEncodeIntegers
#undef X
#define X(ivar) [coder encodeObject:ivar forKey:@"" #ivar];
XEncodeObjects
#undef X
}
-(id) initWithCoder: (NSCoder*) decoder
{
#define X(ivar) [decoder decodeBoolForKey:@"" #ivar];
XEncodeBools
#undef X
#define X(ivar) [decoder decodeIntegerForKey:@"" #ivar];
XEncodeIntegers
#undef X
#define X(ivar) [decoder decodeObjectForKey:@"" #ivar];
XEncodeObjects
#undef X
return self;
}
@interface Foo : NSObject <NSCoder>
@property BOOL aBool;
@property BOOL anotherBool;
@property NSInteger anInteger;
@property NSInteger anotherInteger;
@property NSObject *� anObject;
@property NSObject *� anotherObject;
@end
@implementation Foo
#define XEncodeBools \
X(_aBool) \
X(_anotherBool)
#define XEncodeIntegers \
X(_anInteger) \
X(_anotherInteger)
#define XEncodeObjects \
X(_anObject) \
X(_anotherObject)
#include "XSynthesizeCoders.h"
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment