データオブジェクトをコード化します
-(void)encodeDataObject:(NSData *)data:
解説
データオブジェクトをコード化します。
返り値
( void )
なし
引数
( NSData * )data
データ
フレームワーク
Foundation
クラス
NSCoder
Instance Methods
使用可能
10.0
例文
#import "MyView.h" @implementation MyView //アンアーカイブするときの手順の記述 - (id)initWithCoder:(NSCoder *)decoder { //NSPoint point; //NSRect rect; //NSSize size; void *mPointer; unsigned bBuffer; NSData *dat2 = [[NSData alloc] init]; NSMutableDictionary *aMutableDictionary = [ NSMutableDictionary dictionaryWithCapacity:1 ]; NSZone *zone = [self zone]; intVal = 20; boolVal = NO; NSLog(@"initWithCoder"); NSLog([NSString stringWithFormat:@"systemVersion-%u",[decoder systemVersion]]); NSLog([NSString stringWithFormat:@"systemVersion-%u",[decoder versionForClassName:@"NSCoder"]]); [decoder setObjectZone:zone]; [super initWithCoder:decoder]; mPointer = [decoder decodeBytesWithReturnedLength:&bBuffer]; dat2 = [decoder decodeDataObject]; aMutableDictionary = [decoder decodePropertyList]; NSLog([aMutableDictionary description]); return self; } //アーカイブするときの手順の記述 - (void)encodeWithCoder:(NSCoder *)encoder { //NSMutableData *dat = [NSMutableData data]; NSLog(@"encodeWithCoder"); intVal = 10; boolVal = YES; unsigned char aBuffer[100]; NSString *str = @"This is a pen."; NSData *dat1 = [NSData dataWithBytes:[str cString] length:[str cStringLength]]; NSZone *zone; NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys: @"a",@"あ", @"i",@"い", @"u",@"う",nil]; [dat1 getBytes:aBuffer length:10]; zone = [encoder objectZone]; NSLog(NSZoneName(zone)); [super encodeWithCoder:encoder]; [encoder encodeBytes:aBuffer length:10]; [encoder encodeDataObject:dat1]; [encoder encodePropertyList:dic]; return; } @end