13.07.2015 Views

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

Beginning Objective-C pdf - EBook Free Download

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

322CHAPTER 9: Writing an ApplicationListing 9-60. Adopting the APRemoteAddressBook Delegation Protocol#import "APRemoteAddressBookInterface.h"#import "APRemoteAddressBook.h"#import "APAddressBookClient.h"@interface APRemoteAddressBookBrowser : NSObject@endYou won’t be able to compile this as-is, however, as no class yet exists. Let’s remedy that.Create a new class in the XPC service target named APRemoteAddressBook and enter the codefrom Listing 9-61 in its header file.Listing 9-61. The Remote Address Book Class#import "APRemoteAddressBookInterface.h"@class APRemoteAddressBook;@protocol APRemoteAddressBookDelegate - (void) addressBookDidDisconnect: (APRemoteAddressBook *) book;@end@interface APRemoteAddressBook : NSObject - (id) initWithResolvedService: (NSNetService *) resolvedServicedelegate: (id) delegate;@endThe class itself has a very simple interface—it takes an NSNetService instance from which itwill obtain its communication channels and a delegate. Beyond that, its only API is that definedby the APRemoteAddressBook protocol (and by extension the APAddressBook protocol), seen inListings 9-11 and 9-12.The implementation of this class can be very similar to that used for APAddressBookClient,using dispatch_io and friends to handle data transfer. However, since this is a tutorial, we hadyou use a different, pure <strong>Objective</strong>-C approach for this class. This means that you’ll be usingNSStream objects to transfer data, and you’ll handle concurrency and queuing yourself with anNSOperationQueue and a custom NSOperation.In the sample project, the definitions of the various command dictionary keys are stored in theimplementation file for this class, APRemoteAddressBook.m. If you want to keep yours in the sameplace, you can move them from any other file you’ve used into here to match—the code is inListing 9-41.Class StructureThe instance variables for the class, declared as part of its @implementation block, can be seenin Listing 9-62.www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!