macOS/iOS API解説

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

目次

mutableCopy

オブジェクトの変更可能なコピーを返します

解説

オブジェクトの変更可能なコピーを返します。

返り値

( id )

オブジェクト

引数

クラス

NSObject

Instance Methods

使用可能

10.0

参照

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
	NSString *str = @"aaa";
	id str2 = [str mutableCopy];
	NSLog(@"%@",[str2 className]);
	NSLog(@"str=%@,str2=%@",str,str2);
	//strは変更不可なオブジェクトなのでコンパイル時にエラーとなる
	//[str appendString:@"+addstring"];	
	//str2は変更可能なオブジェクトなので追加可能
	[str2 appendString:@"+addstring"];
	NSLog(@"str=%@,str2=%@",str,str2);
}

@end