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