My class is something like this:
TorneoSingolo.h
@interface TorneoSingolo : NSObject <NSCoding> {
...
NSString *Descrizione;
...
}
- (void)encodeWithCoder:(NSCoder *)encoder;
- (id)initWithCoder:(NSCoder *)decoder;
@property(nonatomic, retain) NSString *Descrizione;
@end
TorneoSingolo.m
@implementation TorneoSingolo
@synthesize Descrizione;
- (void)encodeWithCoder:(NSCoder *)encoder
{
[encoder encodeObject:self.NomeTorneo forKey:@"OBJ_NomeTorneo"];
[encoder encodeObject:NomeSquadra forKey:@"OBJ_NomeSquadra"];
[encoder encodeObject:self.Descrizione forKey:@"OBJ_Descrizione"];
[encoder encodeInt: [self.NumPortieri intValue] forKey:@"OBJ_numportieri"];
}
-(id)initWithCoder:(NSCoder *)decoder
{
self = [self init];
Descrizione = [decoder decodeObjectForKey:@"OBJ_Descrizione"];
[Descrizione retain];
return self;
}
The method that call the loading function works like this:
ElencoTornei2 = [[NSMutableArray alloc] init];
NSData *data;
NSKeyedUnarchiver *unarchiver;
NSString *archivePath = [rootPath stringByAppendingPathComponent:@"ElencoTornei.archive"];
if ([[NSFileManager defaultManager] fileExistsAtPath:archivePath]) {
data = [NSData dataWithContentsOfFile:archivePath];
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
ElencoTornei2 = [unarchiver decodeObjectForKey:@"MyElencoTornei"];
[unarchiver finishDecoding];
[unarchiver release];
[ElencoTornei2 retain];
}
I can't understand where i'm doing something wrong, like reinitialize an object...
please help me... =)