Passing a function as an argument?

I don’t understand the syntax below at all.

“There are three messages that BNRLogger will need to respond to as the delegate of the NSURLConnection. Two are from the NSURLConnectionDataDelegate protocol:

- (void)connection:(NSURLConnection *)connection
didReceiveData:(NSData *)data;

-(void)connectionDidFinishLoading:(NSURLConnection *)connection;

The other is from the NSURLConnectionDelegate protocol:

  -(void)connection:(NSURLConnection *)connection
  didFailWithError:(NSError *)error;

I looked this up in the docs and it’s function signature looked like this:

func connection(NSURLConnection, didReceive: URLResponse)

Does this mean that connectionDidFinishLoading is from NSURLConnectionDataDelegate AND is a function that takes didReceiveData also from NSURLConnectionDataDelegate along with a function from NSURLConnectionDelegate called didFailWithError ?


What does it mean when a method is under another one?

- (void)connection:(NSURLConnection *)connection
    didReceiveData:(NSData *)data;

That is not Objective-C syntax. It looks like you are looking at the Swift documentation. Look at the Objective-C documentation.

That’s just the declaration of the function written on two lines. didReceiveData is not a function; it is an argument label.

The following two declarations are the same:

- (void)connection:(NSURLConnection *)connection
    didReceiveData:(NSData *)data;

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;

Thanks for the response! I think I get it. The series of method names define that method.

Better to use the correct terminology: the series of argument labels, not the series method names.