page 166 Goldstein goes through app initialization
I remembered what the < and > are for! They refer to protocol's. Protocols are a new concept for me. I keep thinking of C3PO in Star Wars telling Luke that he's a protocol droid. Which is REALLY not helpful.
A search on the syntax characters plus the word 'protocol' turned up the following in
http://en.wikipedia.org/wiki/Objective-C
- (void)setMyValue:(id)foo;
In the above statement, foo may be of any class.
- (void)setMyValue:(id<aProtocol>)foo;
In the above statement, foo may still be an instance of any class, but the class must conform to the aProtocol protocol.
.....
So when I look at the initialization code for the DeepThoughtsAppDelegate.h file and I see the line
@interface DeepThoughtsAppDelegate:NSObject <UIApplicationDelegate>
that must mean that MY AppDelegate class (DeepThoughtsAppDelegate), that I'm setting up here is
* A subclass of NSObject AND
* Will conform to the UIApplicationDelegate protocol
Another basic syntax link
http://en.wikibooks.org/wiki/Objective-C_Programming/syntax
// DeepThoughtsAppDelegate.h
// DeepThoughts
//
// Created by xxxxx on 5/30/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@class DeepThoughtsViewController;
@interface DeepThoughtsAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
DeepThoughtsViewController *viewController;
}
I remembered what the < and > are for! They refer to protocol's. Protocols are a new concept for me. I keep thinking of C3PO in Star Wars telling Luke that he's a protocol droid. Which is REALLY not helpful.
A search on the syntax characters plus the word 'protocol' turned up the following in
http://en.wikipedia.org/wiki/Objective-C
- (void)setMyValue:(id)foo;
In the above statement, foo may be of any class.
- (void)setMyValue:(id<aProtocol>)foo;
In the above statement, foo may still be an instance of any class, but the class must conform to the aProtocol protocol.
.....
So when I look at the initialization code for the DeepThoughtsAppDelegate.h file and I see the line
@interface DeepThoughtsAppDelegate:NSObject <UIApplicationDelegate>
that must mean that MY AppDelegate class (DeepThoughtsAppDelegate), that I'm setting up here is
* A subclass of NSObject AND
* Will conform to the UIApplicationDelegate protocol
Another basic syntax link
http://en.wikibooks.org/wiki/Objective-C_Programming/syntax
...
I NEED TO REMEMBER to double check on the use of "@class", which is not in the current book.
I THINK it just means that I can use the DeepThoughtsViewController class from here
// DeepThoughts
//
// Created by xxxxx on 5/30/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@class DeepThoughtsViewController;
@interface DeepThoughtsAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
DeepThoughtsViewController *viewController;
}
Other things I'm interpreting this code as doing is
declaring two instance variables window and viewController that will be part of the DeepThoughtsAppDelegate class. The window ivar is of type UIWindow and the viewController ivar inheirits from DeepThoughtsViewController (probably why I need to put that @class statement in)
* * *
A little less mystery about the code now
No comments:
Post a Comment