Pages

June 12, 2013

Get App Delegate

Getting the App delegate in any iOS project is a common question for most of Objective-C developer. Of course you could use "[[UIApplication sharedApplication] delegate]" method, but I've wrap this code into a more readable function.


/** Returns the App Delegate.

 Usually you need casting the result, such as: MyClassAppDelegate *myAppDel = (MyClassAppDelegate*)[LMFunctions appDelegate];.

 @return Returns the generic object (id) representing the App Delegate.

 */
+ (id)appDelegate {
    return [[UIApplication sharedApplication] delegate];
}



Download the ready-for-use source file (.m) of Get App Delegate

2 comments:

  1. very useful method. thank u for sharing

    ReplyDelete
  2. This is pretty simple but I think it's not so easy to find and remember, so I create this useful method!
    Hope you'll use it :)

    ReplyDelete