プロジェクトにこのクラスのヘッダーがあります。
@interface VideoItem : NSObject <NSCoding> {
NSString *idStr;
NSString *name;
NSString *link;
}
-(id)initWithVideoItem:(VideoItem*)video;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *link;
@property (nonatomic, retain) NSString *idStr;
@end
これは実装です:
@implementation VideoItem
@synthesize name,link,idStr;
-(id)initWithVideoItem:(VideoItem*)video{
if (self = [super init]) {
self.name = video.name;
self.link = video.link;
self.idStr = video.idStr;
}
return self;
}
#pragma mark
#pragma mark NSCoder
- (void)encodeWithCoder:(NSCoder *)encoder{
[encoder encodeObject:self.name forKey:@"video_name"];
[encoder encodeObject:self.link forKey:@"video_link"];
[encoder encodeObject:self.idStr forKey:@"video_id"];
[encoder encodeObject:self.imgUrl forKey:@"video_img"];
[encoder encodeObject:self.viewCount forKey:@"video_views"];
[encoder encodeObject:self.artist forKey:@"video_artist"];
[encoder encodeObject:self.timeStr forKey:@"video_timestr"];
[encoder encodeInt:self.seconds forKey:@"video_secondes"];
[encoder encodeInt:self.rating forKey:@"video_rating"];
[encoder encodeObject:self.pubDate forKey:@"pubDate"];
}
- (id)initWithCoder:(NSCoder *)decoder {
if(self = [super init]){
self.name = [decoder decodeObjectForKey:@"video_name"];
self.link = [decoder decodeObjectForKey:@"video_link"];
self.idStr = [decoder decodeObjectForKey:@"video_id"];
}
return self;
}
@end
dealloc
そして、このような場合にメソッドを追加して文字列を解放する必要があるかどうかを知りたいですか?