Database Reference
In-Depth Information
The #ifdef __OBJC__ should look like this:
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "CTAppDelegate.h"
#define AppDelegate (CTAppDelegate *)[[UIApplication sharedApplication] delegate]
#endif
Now select the main.m file inside the Support Files group.
10.
Change the import statement from AppDelegate to CTAppDelegate .
11.
Change the [AppDelegate class] to [CTAppDelegate class] .
12.
#import <UIKit/UIKit.h>
#import "CTAppDelegate.h"
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([CTAppDelegate
class]));
}
}
Now let's walk through this process. The first thing we did was rename our AppDelegate files to
CTAppDelegate . We did this because we want the filename to be the same as the class name. Next
we changed the class name from AppDelegate to CTAppDelegate . This is done because we want
to access our Application Delegate with the name AppDelegate so it is easily understood what the
variable is.
Then we added the define directive inside the precompiled headers file. This directive creates a
macro that tells the compiler to replace the code we defined in all places that we call the defined
identifier. In our case we will use AppDelegate to access our Application Delegate instead of writing
(CTAppDelegate *)[[UIApplication sharedApplication] delegate] . We provided the import for the
CTAppDelegate as well so that the compiler understands what CTAppDelegate is.
The final step was to update main.m with the correct entry point for the app. Setting the
UIApplicationMain methods fourth parameter to NSStringFromClass([CTAppDelegate class]) tells
main that CTAppDelegate is the name of the class that our delegate is instantiated from. Basically,
this is where our app starts.
Setting Up Your Storyboard
Now let's make a few modifications to our storyboard so that we have the objects already created
that we will reference in code. Set up your storyboard file and save as shown in Figure 4-14 .
 
Search WWH ::




Custom Search