私は次のようなクラスオブジェクトを持っています;
BookEntity.h
import <Cocoa/Cocoa.h>
@interface BookEntity : NSObject<NSCoding> {
NSString *name;
NSString *surname;
NSString *email;
}
@property(copy) NSString *name,*surname,*email;
@end
BookEntity.m
#import "BookEntity.h"
@implementation BookEntity
@synthesize name,surname,email;
- (void) encodeWithCoder: (NSCoder *)coder
{
[coder encodeObject: self forKey:@"appEntity"];
}
- (id) initWithCoder: (NSCoder *)coder
{
if (self = [super init])
{
self = [coder decodeObjectForKey:@"appEntity"];
}
return self;
}
このクラスにいくつかの値を割り当てます
BookEntity *entity = [[BookEntity alloc] init];
entity.name = @"Stewie";
entity.surname = @"Griffin";
entity.email = @"sg@example.com";
NSKeyedArchiver を使用してこのクラスを保存し、NSKeyedUnarchiver で復元したいと考えています。
ファイルに書き込みますが、このファイルを取得すると、エンティティには値が含まれます。
これを行う最善の方法は何ですか?
ありがとう。