Loose-Info.com
Last Update 2013/02/13
TOP - Objective-C - フレームワーク - Foundation - NSObject - +new

allocとinitの組み合わせとなります。

サブクラスで再実装されるinit...などについての詳細は、XCodeのデベロッパドキュメントのNSObject Class Referenceを参照してください。

+ (id)new

(例)
※ Xcodeで生成される「***_Prefix.pch」などのファイルの内容は記載しません。

実行例
#import <Foundation/Foundation.h> @interface MyTestClass1 : NSObject @end @implementation MyTestClass1 @end int main (void) { NSLog(@"[[NSObject alloc] init] : %@", [[[NSObject alloc] init] description]); NSLog(@"[NSObject new] : %@", [[NSObject new] description]); NSLog(@"[[MyTestClass1 alloc] init] : %@", [[[MyTestClass1 alloc] init] description]); NSLog(@"[MyTestClass1 new] : %@", [[MyTestClass1 new] description]); return 0; }

実行結果
[[NSObject alloc] init] : <NSObject: 0x2000107e0> [NSObject new] : <NSObject: 0x200010ee0> [[MyTestClass1 alloc] init] : <MyTestClass1: 0x200010840> [MyTestClass1 new] : <MyTestClass1: 0x20000d0a0>