macOS/iOS API解説

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

目次

-valueWithNonretainedObject:

値オブジェクトをオブジェクトで作って返します
+(NSValue *)valueWithNonretainedObject:(id)anObject:

山梨県産 もも 光糖度センサー選別 1箱 3kg

山梨県産 もも 光糖度センサー選別 1箱 3kg

解説

値オブジェクトをオブジェクトで作って返します。
オブジェクトの保持(retain)は行いません。

value:withObjCType:を下記の方法で呼び出したのと同じ結果になります。
NSValue *theValueOfPointer = [NSValue valueWithBytes:&anObject objCType:@encode(void *)];

オブジェクトを保持することなくコレクションオブジェクト(NSArrayやNSDictionary)に入れる時に使います。

返り値

( NSValue * )

値オブジェクト

引数

( id )anObject

オブジェクト

クラス

NSValue

Class Methods

使用可能

10.0

参照

- nonretainedObjectValue

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{

	//単にポインタを渡す場合
	id anObject = @"Obj-C string";
	NSValue *theValueOfPointer = [NSValue valueWithBytes:&anObject objCType:@encode(void *)];
	id theObjPointer;
	[theValueOfPointer getValue:&theObjPointer];
	NSLog(@"---%@",theObjPointer);

	//上の例を書き換えるとこうなる
	NSValue *theValueOfObj = [NSValue valueWithNonretainedObject:@"Obj-C string"];
	id theObj;
	[theValueOfObj getValue:&theObj];
	NSLog(@"---%@",theObj);


}

@end