Object serialization: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 947: | Line 947: | ||
int numberOfLegs; |
int numberOfLegs; |
||
} |
} |
||
- (id) init; |
|||
- (id) initWithName: (NSString*)name andLegs: (NSInteger)legs; |
- (id) initWithName: (NSString*)name andLegs: (NSInteger)legs; |
||
- (void) dump; |
- (void) dump; |
||
Line 956: | Line 955: | ||
@implementation Animal |
@implementation Animal |
||
- (id) init |
|||
{ |
|||
self = [super init]; |
|||
return self; |
|||
} |
|||
- (id) initWithName: (NSString*)name andLegs: (NSInteger)legs |
- (id) initWithName: (NSString*)name andLegs: (NSInteger)legs |
||
{ |
{ |
||
self = [super init] |
if ((self = [super init])) { |
||
animalName = [name retain]; |
animalName = [name retain]; |
||
numberOfLegs = legs; |
numberOfLegs = legs; |
||
} |
|||
return self; |
return self; |
||
} |
} |
||
Line 985: | Line 980: | ||
- (id) initWithCoder: (NSCoder*)coder |
- (id) initWithCoder: (NSCoder*)coder |
||
{ |
{ |
||
self = [super init] |
if ((self = [super init])) { |
||
animalName = [[coder decodeObjectForKey: @"Animal.name"] retain]; |
animalName = [[coder decodeObjectForKey: @"Animal.name"] retain]; |
||
numberOfLegs = [coder decodeIntForKey: @"Animal.legs"]; |
numberOfLegs = [coder decodeIntForKey: @"Animal.legs"]; |
||
} |
|||
return self; |
return self; |
||
} |
} |
||
Line 997: | Line 993: | ||
NSMutableArray *eatenList; |
NSMutableArray *eatenList; |
||
} |
} |
||
- (id) init; |
|||
- (id) initWithName: (NSString*)name hasFur: (BOOL)fur; |
- (id) initWithName: (NSString*)name hasFur: (BOOL)fur; |
||
- (void) addEatenThing: (NSString*)thing; |
- (void) addEatenThing: (NSString*)thing; |
||
Line 1,009: | Line 1,004: | ||
- (id) init |
- (id) init |
||
{ |
{ |
||
self = [super init] |
if ((self = [super init])) { |
||
hasFur = NO; |
hasFur = NO; |
||
eatenList = [[NSMutableArray alloc] initWithCapacity: 10]; |
eatenList = [[NSMutableArray alloc] initWithCapacity: 10]; |
||
} |
|||
return self; |
return self; |
||
} |
} |
||
- (id) initWithName: (NSString*)name hasFur: (BOOL)fur |
- (id) initWithName: (NSString*)name hasFur: (BOOL)fur |
||
{ |
{ |
||
self = [super initWithName: name andLegs: 4] |
if ((self = [super initWithName: name andLegs: 4])) { |
||
hasFur = fur; |
hasFur = fur; |
||
eatenList = [[NSMutableArray alloc] initWithCapacity: 10]; |
eatenList = [[NSMutableArray alloc] initWithCapacity: 10]; |
||
} |
|||
return self; |
return self; |
||
} |
} |
||
Line 1,052: | Line 1,049: | ||
- (id) initWithCoder: (NSCoder*)coder |
- (id) initWithCoder: (NSCoder*)coder |
||
{ |
{ |
||
self = [super initWithCoder: coder] |
if ((self = [super initWithCoder: coder])) { |
||
hasFur = [coder decodeBoolForKey: @"Mammal.hasFur"]; |
hasFur = [coder decodeBoolForKey: @"Mammal.hasFur"]; |
||
eatenList = [[coder decodeObjectForKey: @"Mammal.eaten"] retain]; |
eatenList = [[coder decodeObjectForKey: @"Mammal.eaten"] retain]; |
||
} |
|||
return self; |
return self; |
||
} |
} |