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

- 出版社/メーカー: 株式会社 自然の恵み
- メディア: その他
- この商品を含むブログを見る
解説
値オブジェクトをオブジェクトで作って返します。
オブジェクトの保持(retain)は行いません。
value:withObjCType:を下記の方法で呼び出したのと同じ結果になります。
NSValue *theValueOfPointer = [NSValue valueWithBytes:&anObject objCType:@encode(void *)];
オブジェクトを保持することなくコレクションオブジェクト(NSArrayやNSDictionary)に入れる時に使います。
返り値
( NSValue * )
値オブジェクト
引数
( id )anObject
オブジェクト
フレームワーク
Foundation
クラス
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