macOS/iOS API解説

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

目次

encodeValuesOfObjCTypes:

INDEX>Foundation>NSCoder>

オブジェクティブCタイプの値をコード化します
-(void)encodeValuesOfObjCTypes:(const char *)valueTypes, ...:

解説

オブジェクティブCタイプの値をコード化します。引数は値タイプと値が交互に並びます。

返り値

( void )

なし

引数

( const char * )valueTypes, ...

値タイプ

クラス

NSCoder

Instance Methods

使用可能

10.0

参照

- encodeArrayOfObjCType:count:at:
- encodeValueOfObjCType:at:

例文

#import "MyView.h"

@implementation MyView

//アンアーカイブするときの手順の記述
- (id)initWithCoder:(NSCoder *)decoder
{
    int intRetVal;
    BOOL boolRetVal;
    
    NSLog(@"initWithCoder");
    [super initWithCoder:decoder];

    
    [decoder decodeValuesOfObjCTypes:@encode(int),&intRetVal,@encode(BOOL),&boolRetVal];
    NSLog([NSString stringWithFormat:@"intVal = %d",intRetVal]);
        if (boolRetVal){
            NSLog(@"YES");
        }else{
            NSLog(@"NO");
        }
    
    
    return self;
}
//アーカイブするときの手順の記述
- (void)encodeWithCoder:(NSCoder *)encoder
{
    intVal = 10;
    boolVal = YES;
    floatVal = 100.5;
    
    NSLog(@"encodeWithCoder");
    [super encodeWithCoder:encoder];
    [encoder encodeValuesOfObjCTypes:@encode(int),&intVal,@encode(BOOL),&boolVal];

    return;
}
@end