Created
June 20, 2012 15:05
-
-
Save dchohfi/2960341 to your computer and use it in GitHub Desktop.
NSCoding protocol
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
#import <Foundation/Foundation.h> | |
@interface Contato : NSObject <NSCoding> | |
@property (nonatomic, retain) NSString *nome; | |
@property (nonatomic, retain) NSString *email; | |
@property (nonatomic, retain) NSString *endereco; | |
@property (nonatomic, retain) NSString *telefone; | |
@property (nonatomic, retain) NSString *site; | |
@property (nonatomic, retain) UIImage *imagem; | |
@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
#import "Contato.h" | |
@implementation Contato | |
@synthesize nome, site, email, imagem, endereco, telefone; | |
- (void)encodeWithCoder:(NSCoder *)aCoder { | |
[aCoder encodeObject:nome forKey:@"nome"]; | |
[aCoder encodeObject:site forKey:@"site"]; | |
[aCoder encodeObject:email forKey:@"email"]; | |
[aCoder encodeObject:imagem forKey:@"imagem"]; | |
[aCoder encodeObject:endereco forKey:@"endereco"]; | |
[aCoder encodeObject:telefone forKey:@"telefone"]; | |
} | |
- (id)initWithCoder:(NSCoder *)aDecoder { | |
self = [super init]; | |
if(self){ | |
[self setNome:[aDecoder decodeObjectForKey:@"nome"]]; | |
[self setEndereco:[aDecoder decodeObjectForKey:@"endereco"]]; | |
[self setSite:[aDecoder decodeObjectForKey:@"site"]]; | |
[self setImagem:[aDecoder decodeObjectForKey:@"imagem"]]; | |
[self setEmail:[aDecoder decodeObjectForKey:@"email"]]; | |
[self setTelefone:[aDecoder decodeObjectForKey:@"telefone"]]; | |
} | |
return self; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment