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
{
#ifdef XEncodeBools
#define X(ivar) [coder encodeBool:ivar forKey:@"" #ivar];
XEncodeBools
#undef X
#ifndef XSynthesizeCodersFoundSources
#define XSynthesizeCodersFoundSources
#endif
#endif
#ifdef XEncodeDoubles
#define X(ivar) [coder encodeDouble:ivar forKey:@"" #ivar];
XEncodeDoubles
#undef X
#ifndef XSynthesizeCodersFoundSources
#define XSynthesizeCodersFoundSources
#endif
#endif
#ifdef XEncodeIntegers
#define X(ivar) [coder encodeInteger:ivar forKey:@"" #ivar];
XEncodeIntegers
#undef X
#ifndef XSynthesizeCodersFoundSources
#define XSynthesizeCodersFoundSources
#endif
#endif
#ifdef XEncodeObjects
#define X(ivar) [coder encodeObject:ivar forKey:@"" #ivar];
XEncodeObjects
#undef X
#ifndef XSynthesizeCodersFoundSources
#define XSynthesizeCodersFoundSources
#endif
#endif
}
-(id) initWithCoder: (NSCoder*) decoder
{
#ifdef XEncodeBools
#define X(ivar) [decoder decodeBoolForKey:@"" #ivar];
XEncodeBools
#undef X
#endif
#ifdef XEncodeIntegers
#define X(ivar) [decoder decodeIntegerForKey:@"" #ivar];
XEncodeIntegers
#undef X
#endif
#ifdef XEncodeDoubles
#define X(ivar) [decoder decodeDoubleForKey:@"" #ivar];
XEncodeDoubles
#undef X
#endif
#ifdef XEncodeObjects
#define X(ivar) [decoder decodeObjectForKey:@"" #ivar];
XEncodeObjects
#undef X
#endif
return self;
}
#ifndef XSynthesizeCodersFoundSources
#warning XSynthesizeCoders found none of XEncodeBools, XEncodeIntegers, XEncodeDoubles or XEncodeObjects
#endif
@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