Verification


#1

Despite the fact that I have made this far in the book I think I just realized something that I did not understand about “Delegates”.

I noticed that in implementing the NSURLConnection delegate methods in this chapter, the three methods implemented had the connection argument supplied on each of them and was called “theConnection”. This is obviously not the ivar holding the connection pointer in our class so I think doing this forced me to understand that it is the NSURLConnection itself calling the delegate methods and placing itself in that first argument position. The fact that that argument is not used in any of our overrides in this example is not important to my question, but just for verification:

[ul]The actual NSURLConnection when it was allocated and initialized, designated this class as its delegate; so when this class’s connection (no matter what it is called) is used, the pointer to that connection is placed as the first argument in the these delegate methods.

From this, and before I try the challenge at the end of the chapter, in general a delegate, and any delegate methods (if implemented), has the object that it is a delegate of available via a pointer to it, just because it was specified as the delegate.[/ul]

Hopefully I got my idea across here, and it is correct, because if so, a light bulb just popped on.

-Lou


#2

I would state it somewhat differently, but it sounds like you may be on the right track.

  • The NSURLConnection doesn’t designate this class as its delegate; rather we (the ScheduleFetcher in this case) assign ourselves as its delegate. The convention of delegate protocols is that the first argument will be the object that is sending the message to its delegate. We call it theConnection so that it doesn’t collide with any existing i-vars named connection.

  • Oftentimes a class which acts as a delegate (ScheduleFetcher) will keep a reference to the object it is the delegate of, although this is not necessary.

Adam


#3

Thanks Adam, I didn’t state it plainly enough, but you were able to understand what I was trying to get to and verified what I was thinking.