Graphics Programs Reference
In-Depth Information
- (void)locationManager:(CLLocationManager *)manager
didUpdateHeading:(CLHeading *)newHeading;
- (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager;
- (void)locationManager:(CLLocationManager *)manager
didEnterRegion:(CLRegion *)region;
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error;
@end
This protocol, like all protocols, is declared with the directive @protocol followed by
its name, CLLocationManagerDelegate . The NSObject in angled brackets refers
to the NSObject protocol and tells us that CLLocationManagerDelegate includes
all of the methods in the NSObject protocol. The methods specific to CLLoca-
tionManagerDelegate are declared next, and the protocol is closed with an @end
directive.
Note that a protocol is not a class; it is simply a list of methods. You cannot create in-
stances of a protocol, it cannot have instance variables, and these methods are not imple-
mented anywhere in the protocol. Instead, implementation is left to each class that con-
forms to the protocol.
We call protocols used for delegation delegate protocols , and the naming convention for a
delegate protocol is the name of the delegating class plus the word Delegate . Not all
protocols are delegate protocols, however, and we will see an example of a different kind
of protocol in the next chapter.
The protocols we've mentioned so far are part of the iOS SDK, but you can also write
your own protocols. We'll do that later in Chapter 13 and Chapter 26 .
Protocol methods
In the CLLocationManagerDelegate protocol, we see two kinds of methods: meth-
ods that handle information updates and methods that handle requests for input. For ex-
ample, the location manager's delegate implements the locationMan-
ager:didEnterRegion: method if it wants to hear from the location manager that
the device has entered a particular region. This is an information update.
On the other hand, locationManagerShouldDisplayHeadingCalibration:
is a request for input. A location manager sends its delegate this message to ask if it
should display the heading calibration. The method returns a Boolean value, which is the
delegate's answer.
Search WWH ::




Custom Search