0

When would the application parameter in any of the app delegates not be equal to the shared instance?

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{  
  UIApplication* sharedapp = [UIApplication sharedApplication];
  if(application == sharedapp){
    //things are as I expect
  }else{
    //some other situation I can't think of
  }
}
Nick
  • 2,735
  • 1
  • 29
  • 36
  • 1
    The idea of the `application` parameter is so you don't need to call `[UIApplication sharedApplication]`. – rmaddy Dec 05 '15 at 19:15

2 Answers2

1

No, there wouldn't be any situation like that.

From Documentation:

Every app has exactly one instance of UIApplication. When an app is launched, the system calls the UIApplicationMain function; among its other tasks, this function creates a singleton UIApplication object. Thereafter you access the object by calling the sharedApplication class method.

Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
1

The call to [UIApplication sharedApplication] will always return a pointer to your app's shared application object. That's what the method is for.

What is the variable sharedApp you are comparing against? Presumably that's an instance variable that you defined and set to contain a pointer to your application object with an identical call to [UIApplication sharedApplication]?

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • Yes, exactly. This is just an illustration of my question. I am scratching my head on why the delegate would have application passed in if its available via [UIApplication sharedApplication].... I suppose its just there for convenience, since maybe a common pattern is to update the badge? – Nick Dec 05 '15 at 18:02