macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

decodeBytesWithReturnedLength:

重複?タイプが明記されていないデータのバッファをデコードします。
-(void *)decodeBytesWithReturnedLength:(unsigned *)numBytes:

解説

タイプが明記されていないデータのバッファをデコードします。

返り値

( void * )

返されるデータのポインタ

引数

( unsigned * )numBytes

返されるバッファの長さのポインタ

クラス

NSCoder

Instance Methods

使用可能

10.0

参照

- encodeArrayOfObjCType:count:at:

例文

#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