views:

73

answers:

1

This is a follow-on from a previous question, in the implementation, I have two methods, one which gets called when a particular service is found and the other when it vanishes. This might be a dumb question, but apart from the NSLog lines they are identical, what dictates which gets called?

// INTERFACE
@interface ITunesFinder : NSObject <NSNetServiceBrowserDelegate>
@end

.

// IMPLEMENT
@implementation ITunesFinder

// ------------------------------------------------------------------- **
-(void) netServiceBrowser: (NSNetServiceBrowser *) browser
           didFindService: (NSNetService *) service
               moreComing: (BOOL) moreComing {
    [service resolveWithTimeout:10];
    NSLog(@"Service Found: %@", [service name]);
}

// ------------------------------------------------------------------- **
-(void) netServiceBrowser: (NSNetServiceBrowser *) browser
         didRemoveService: (NSNetService *) service
               moreComing: (BOOL) moreComing {
    [service resolveWithTimeout:10];
    NSLog(@"Service Lost!: %@", [service name]);
}
@end

gary

+4  A: 

They are not identical. The one has a parameter: didFindService and the other has a parameter didRemoveService.

rein
it's not a parameter, it's part of the method name.
Dave DeLong
Ah indeed they do, many thanks. I think I need to take a break, I have been looking at that for 30mins and scratching my head.
fuzzygoat
So basically what we have is two different method names, accessed via the browser delegate ITunesFinder.
fuzzygoat
@Dave - have a look at Figure 2 on this page: http://developer.apple.com/iphone/library/referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/
rein
@fuzzygoat - yes, correct. The methods have different signatures based on the fact that their parameter names differ.
rein
@Dave - I must apologize - they are not parameter names but "method definition keywords".
rein
@rein - np. selectors in objc are strange and take some getting used to. =)
Dave DeLong
Thanks for the primer link, I have not seen that before. I will print it and have a read right now.
fuzzygoat