Skip to content

Instantly share code, notes, and snippets.

@epatel
Created September 11, 2011 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epatel/1209907 to your computer and use it in GitHub Desktop.
Save epatel/1209907 to your computer and use it in GitHub Desktop.
UIImage encoderWithCoder: and initWithCoder: (PNG style)
#import <Foundation/Foundation.h>
@interface UIImage (NSCoder)
- (void)encodeWithCoder:(NSCoder*)encoder;
- (id)initWithCoder:(NSCoder*)decoder;
@end
#import "UIImage+NSCoder.h"
@implementation UIImage (NSCoder)
- (void)encodeWithCoder:(NSCoder*)encoder
{
[encoder encodeDataObject:UIImagePNGRepresentation(self)];
}
- (id)initWithCoder:(NSCoder*)decoder
{
return [self initWithData:[decoder decodeDataObject]];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment