A beginners question about protocols.

Discussion in 'iOS Programming' started by ObjectiveV, Jul 12, 2012.

  1. ObjectiveV macrumors newbie

    Nov 3, 2011
    This may be a dumb question but I'm a bit confused about where i should and should not declare that I implement a protocol.

    Ive been trying to just download the results of a http request to a NSString and most the tutorials i went to lead me to write this block

    webdata = [NSMutableData new];
        NSString *urlString = [NSString stringWithFormat:@"http://www.google.com"];
        myConnection =[NSURLConnection connectionWithRequest:
                       [NSURLRequest requestWithURL:
                        [NSURL URLWithString:urlString]] 
    Everything works fine, but why didn't the compiler yell at me for not stating that I am implementing the protocol NSURLConnection would need to to comply to to be its delegate?

    If for nothing else, stating that I'm going to implement a protocol lets xcode help me a bit more in its auto completion.

    So why does it let me do this? Should I still state that I implement the NSURLConnectionDelegate protocol just to be sure?

    Thanks for any advice.
  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    All the protocol methods are optional. That's probably why.

    Sure, why not.

Share This Page