実装する必要が.h
ありますが、オブジェクト数は常に 0 です....m
NSCoding
mutableArray
.h
#import <Foundation/Foundation.h>
@interface Favorite : NSObject <NSCoding> {
NSMutableArray *myArray;
}
@property (nonatomic, retain) NSMutableArray *myArray;
@end
.m
#import "Favorite.h"
@implementation Favorite
- (void)dealloc {
[myArray release];
}
- (void)encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:myArray];
}
- (id)initWithCoder:(NSCoder *)decoder {
myArray = [[decoder decodeObject] retain];
return self;
}
@end
このクラスを次のように使用します
Favorite *fav = [[Favorite alloc] init];
fav.myArray = self.anotherArray;
[fav release];
それが正しいか??