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

クラスまたはカテゴリがランタイムに加えられる際に呼び出されます。
スーパークラスの+loadが先に実行されます。

+ (void)load

実装されている場合、自動的に実行

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

実行例
#import <Foundation/Foundation.h> @interface MyTestClass1 : NSObject + (void)load; @end @implementation MyTestClass1 + (void)load { NSLog(@"--------------------------"); NSLog(@"MyTestClass1 initialize"); NSLog(@"[self description] → %@", [self description]); NSLog(@"[[MyTestClass1 class] description] → %@", [[MyTestClass1 class] description]); } @end @interface MyTestClass2 : MyTestClass1 + (void)load; @end @implementation MyTestClass2 + (void)load { NSLog(@"--------------------------"); NSLog(@"MyTestClass2 initialize"); NSLog(@"[self description] → %@", [self description]); NSLog(@"[[MyTestClass2 class] description] → %@", [[MyTestClass2 class] description]); } @end int main (void) { NSLog(@"クラス呼び出し前\n"); MyTestClass2 *test2 = [[MyTestClass2 alloc] init]; return 0; }

実行結果
-------------------------- MyTestClass1 initialize [self description] → MyTestClass1 [[MyTestClass1 class] description] → MyTestClass1 -------------------------- MyTestClass2 initialize [self description] → MyTestClass2 [[MyTestClass2 class] description] → MyTestClass2 クラス呼び出し前