What is self in application:didFinishLaunchingWithOptions:


I understand that self always represents the current object, analogous to the this pointer in C++. I’m a bit confused as to what object self refers to right after this method:

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // <-- Here

Does self refer to the instance of the HeavyApplicationDelegate, because the HeavyAppDelegate class conforms to the UIApplicationDelegate protocol? Thanks.


You’re mixing together two concepts here.

application:didFinishLaunchingWithOptions: is sent to the HeavyAppDelegate because it is the delegate of the UIApplication object. In order to be the delegate of the UIApplication, an object must conform to the UIApplicationDelegate protocol.

Once inside this method, self will refer to the instance of HeavyAppDelegate because that is the object running this method.