When I compile the code below I get the following warning: Incompatible type sending "ITunesFinder *" expected "id"? I am only just starting out and to be truthful am a little confused by this example. I would be interested to know if there is a way to write this example without using the delegate class?
I am also a little confused by the class implementation, the book does not describe what this is based on, or for that matter what Categories, Protocols or Delegates do, nor how they work.
here is the code ...
// INTERFACE
#import <Cocoa/Cocoa.h>
@interface ITunesFinder : NSObject
@end
.
// IMPLEMENTATION
#import "ITunesFinder.h"
@implementation ITunesFinder
-(void) netServiceBrowser: (NSNetServiceBrowser *) b
didFindService: (NSNetService *) service
moreComing: (BOOL) moreComing {
[service resolveWithTimeout:10];
NSLog(@"Service Found: %@", [service name]);
}
-(void) netServiceBrowser: (NSNetServiceBrowser *) b
didRemoveService: (NSNetService *) service
moreComing: (BOOL) moreComing {
[service resolveWithTimeout:10];
NSLog(@"Service Lost!: %@", [service name]);
}
@end
.
// MAIN
#import <Foundation/Foundation.h>
#import "ITunesFinder.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSNetServiceBrowser *browser = [[NSNetServiceBrowser alloc] init];
ITunesFinder *finder = [[ITunesFinder alloc] init];
NSLog(@"iTunesFinder ... Start");
[browser setDelegate: finder]; // <<< Warning here !!!!
[browser searchForServicesOfType: @"_daap._tcp" inDomain:@"local."];
NSLog(@"Browsing ...");
[[NSRunLoop currentRunLoop] run];
// Clean up
[browser release];
[finder release];
[pool drain];
return 0;
}
any pointers / wisdom would be much appreciated.
gary