The application delegate

When an iOS application first launches, there is a lot of behind-the-scenes setting up. During this phase, an instance of UIApplication is created to control your 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).

While the application is being launched, it is not ready for work or input. When this changes, the UIApplication instance sends its delegate the message application:didFinishLaunchingWithOptions:. This method is very important. It’s where you put everything that needs to happen or needs to be in place before the user interacts with the application.

In iTahDoodle, one of the things we need to do in this method is find the property list and load it into an array. In BNRAppDelegate.m, notice that there is already a stub for the application:didFinishLaunchingWithOptions: method. Find it and replace the code between its braces with the following:

#​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​
{​
 ​ ​/​/​ ​A​t​t​e​m​p​t​ ​t​o​ ​l​o​a​d​ ​a​n​ ​e​x​i​s​t​i​n​g​ ​t​o​-​d​o​ ​d​a​t​a​s​e​t​ ​f​r​o​m​ ​a​n​ ​a​r​r​a​y​ ​s​t​o​r​e​d​ ​t​o​ ​d​i​s​k​.​
 ​ ​ ​ ​N​S​A​r​r​a​y​ ​*​p​l​i​s​t​ ​=​ ​[​N​S​A​r​r​a​y​ ​a​r​r​a​y​W​i​t​h​C​o​n​t​e​n​t​s​O​f​F​i​l​e​:​d​o​c​P​a​t​h​(​)​]​;​
 ​ ​ ​ ​i​f​ ​(​p​l​i​s​t​)​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​/​/​ ​I​f​ ​t​h​e​r​e​ ​w​a​s​ ​a​ ​d​a​t​a​s​e​t​ ​a​v​a​i​l​a​b​l​e​,​ ​c​o​p​y​ ​i​t​ ​i​n​t​o​ ​o​u​r​ ​i​n​s​t​a​n​c​e​ ​v​a​r​i​a​b​l​e​.​
 ​ ​ ​ ​ ​ ​ ​ ​t​a​s​k​s​ ​=​ ​[​p​l​i​s​t​ ​m​u​t​a​b​l​e​C​o​p​y​]​;​
 ​ ​ ​ ​}​ ​e​l​s​e​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​/​/​ ​O​t​h​e​r​w​i​s​e​,​ ​j​u​s​t​ ​c​r​e​a​t​e​ ​a​n​ ​e​m​p​t​y​ ​o​n​e​ ​t​o​ ​g​e​t​ ​u​s​ ​s​t​a​r​t​e​d​.​
 ​ ​ ​ ​ ​ ​ ​ ​t​a​s​k​s​ ​=​ ​[​[​N​S​M​u​t​a​b​l​e​A​r​r​a​y​ ​a​l​l​o​c​]​ ​i​n​i​t​]​;​
 ​ ​ ​ ​}​
}​

Wondering about the #pragma mark at the start of this code? Objective-C programmers often use this construct to group their methods within a class. Xcode knows about it, too. On the navigation bar at the top of the editor, find the item to the right of BNRAppDelegate.m. (Right now, this item probably reads @implementation AppDelegate, but it depends on where your cursor is in the code.) Click on this item, and Xcode will show you a list of locations in this file. You can click on any of these to be taken to that location in the code. Notice that your new pragma mark shows up on this list. This is very handy when you have many methods in a class.

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

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