The application delegate

When an iOS application first launches, a lot of setup is happening behind the scenes. An instance of UIApplication is created to control the application’s state and act as liaison to the operating system. An instance of BNRAppDelegate is also created and set as the delegate of the UIApplication instance (which explains the name app delegate).

This makes BNRAppDelegate a busy class. In fact, all of the code that you will write for this application will be in BNRAppDelegate.m. It would be good to have a way to organize the class so that it would be easy to find methods quickly. You can use #pragma mark to group methods within a class for easier navigation.

In BNRAppDelegate.m, add a #pragma mark that identifies the existing methods as application delegate callbacks:

#​i​m​p​o​r​t​ ​"​B​N​R​A​p​p​D​e​l​e​g​a​t​e​.​h​"​

@​i​m​p​l​e​m​e​n​t​a​t​i​o​n​ ​B​N​R​A​p​p​D​e​l​e​g​a​t​e​

#​p​r​a​g​m​a​ ​m​a​r​k​ ​-​ ​A​p​p​l​i​c​a​t​i​o​n​ ​d​e​l​e​g​a​t​e​ ​c​a​l​l​b​a​c​k​s​

-​ ​(​B​O​O​L​)​a​p​p​l​i​c​a​t​i​o​n​:​(​U​I​A​p​p​l​i​c​a​t​i​o​n​ ​*​)​a​p​p​l​i​c​a​t​i​o​n​
d​i​d​F​i​n​i​s​h​L​a​u​n​c​h​i​n​g​W​i​t​h​O​p​t​i​o​n​s​:​(​N​S​D​i​c​t​i​o​n​a​r​y​ ​*​)​l​a​u​n​c​h​O​p​t​i​o​n​s​
{​

.​.​.​

Next, on the navigation bar at the top of the editor area, find the item to the right of BNRAppDelegate.m. Click this item, and Xcode will show you a list of locations in this file. You can click any of the method names to be taken directly to that method’s implementation. Notice that your pragma mark appears at the top.

Figure 31.7  Navigating using pragma mark

Navigating using pragma mark

Currently, the BNRAppDelegate class only contains application delegate callbacks. But soon you will add methods with different roles and will use #pragma mark to group them.

The first application delegate callback under the pragma mark is application:didFinishLaunchingWithOptions:. This method is very important. While the application is being launched, it is not ready for work or input. When the application becomes ready, the UIApplication instance sends its delegate the message application:didFinishLaunchingWithOptions:. It is where you put everything that needs to be done before the user interacts with the application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset