Utility based로 프로젝트를 생성하면 appdelegate.h 소스엔 아래 처럼 되어 있습니다.

TestUtilDelegateApp.h

#import <UIKit/UIKit.h>


@class RootViewController;


@interface TestUtilAppDelegate : NSObject <UIApplicationDelegate> {

    UIWindow *window;

    RootViewController *rootViewController;

}


@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet RootViewController *rootViewController;


@end


그러나 소스 어디에도 어떻게 이 클래스가 생성되는지 적혀있지 않습니다.
하지만 실행하면 동작을 하지요.

main.m에는 다음과 같이 되어 있습니다.

main.m

#import <UIKit/UIKit.h>


int main(int argc, char *argv[]) {

    

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    int retVal = UIApplicationMain(argc, argv, nil, nil);

    [pool release];

    return retVal;

}



UIApplicationMain은 아래와 같으며 4번쨰 delegateClass는 Nil이므로 UIApplication클래스가 되고
3번째 principalClassName은 nil이므로 info.plist에 있는 값을 사용하게 됩니다.

UIApplicaitonMain API

int UIApplicationMain ( int argc,  char *argv[], 
NSString *principalClassName, NSString *delegateClassName );


info.plist에는 MainWindow.xib 정보가 들어 있습니다.


MainWindow.xib는 File's Owner는 UIApplication이고 delegate가 된 것이 Test Util Application이다 그리고 이 Test Util App의 Inspector를 보면 TestUtilAppDelegate 클래스로 설정되어 있습니다.


마찬가지로 RootViewController에 대해서도 MainWindow.xib의 Root View Controller로 설정되어 있습니다.

UIApplicationMain 안에서 xib의 어떤 클래스와 연결되어 있는지 확인 한 후 여기에 설정한 클래스를 인스턴스 하게 되는 것입니다.

+ Recent posts