Search code examples
iosiphoneobjective-cdelegatesuiapplicationdelegate

What is a "delegate" in Objective C's iPhone development?


What is a "delegate" in Objective C's iPhone development?


Solution

  • See this discussion

    A delegate allows one object to send messages to another object when an event happens. For example, if you're downloading data from a web site asynchronously using the NSURLConnection class. NSURLConnection has three common delegates:

     - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
     - (void)connectionDidFinishLoading:(NSURLConnection *)connection
     - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    

    One or more of these delegates will get called when NSURLConnection encounters a failure, finishes successfully, or received a response from the web site, respectively.