| Home 目次>Foundation>NSCoder このサイトはこちらに移転しました。 | |
encodePropertyList:
プロパティリストをコード化します
-(void) encodePropertyList:(id)aPropertyList
【返り値】 | |
| void | なし |
| 【パラメータ】 | |
| aPropertyList | プロパティリスト |
【解説】
プロパティリストをコード化します。
【例文】
#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
![]() | |
この記事を評価してください。
| Home 目次>Foundation>NSCoder | 修正日2007.3.22 |