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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 9: Writing an Application 283To handle custom objects within a collection, you would provide some additions to the classwhitelist for the NSXPCInterface defining the receiver of the relevant message. The same appliesif the collection is being provided to a caller-passed reply block. The code excerpted inListing 9-15 shows how this would normally be achieved.Listing 9-15. Passing Custom Objects in an XPC Collection@interface MyCustomObject...@end@protocol MyFilter - (void) filterObjects: (NSArray *) objectsreply: (void (^)(NSArray * filtered)) reply;@end...- (void) listener: (NSXPCListener *) listenershouldAcceptConnection: (NSXPCConnection *) connection{NSXPCInterface * myInterface =[NSXPCInterface interfaceWithProtocol: @protocol(MyFilter)];// define the class whitelistNSSet * expectedClasses = [NSSet setWithObject: [MyCustomObject class]];// set this list for the input collection...[myInterface setClasses: expectedClassesforSelector: @selector(filterObjects:reply:)argumentIndex: 0 // the first parameterofReply: NO]; // an argument of the method itself// ...and also on the collection passed to the reply block[myInterface setClasses: expectedClassesforSelector: @selector(filterObjects:reply:)argumentIndex: 0 // the first parameterofReply: YES];}connection.exportedInterface = myInterface;...In your application, you won’t be sending custom objects across the XPC connection. You will,however, be vending objects by proxy. This has a slightly different implementation—rather thanspecifying a class whitelist for a message parameter, you specify an NSXPCInterface describingthe object to be proxied. Once you have the interface defined, you inform your main interface bycalling a method very similar to the one used to update the class whitelist.In the primary interface defined by the APRemoteAddressBookBrowser protocol there are two suchobjects. The first is the APAddressBook-conforming object passed into -vendAddressBook:www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!