ConnectionKit updates no.3: Delegate communication

CKConnection operates asynchronously, sending delegate message each time it completes an operation. Until recently, this was kind of a pain for subclasses to implement. For example, to notify the delegate that the a directory was created, a CKAbstractConnection subclass had to do:

if (_flags.createDirectory)
											    [_forwarder connection:self didCreateDirectory:path error:nil];

Somewhat messy looking, I'm sure you'll agree. To solve this, I've introduced the CKConnectionClient protocol. It operates a lot like NSURLProtocolClient, so the code above becomes:

[[self client] connectionDidCreateDirectory:path error:nil];

The client then sends the appropriate message to the delegate if it is implemented, and does so on the correct thread. Furthermore, for more complex behaviour like -connectionDidReceiveAuthenticationChallenge:, the client will automatically provide a proposed credential, and follow the standard authentication behaviour if required.

© Mike Abdullah 2007-2015