A beginners question about protocols.

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

  1. ObjectiveV macrumors newbie

    Joined:
    Nov 3, 2011
    #1
    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

    Code:
    webdata = [NSMutableData new];
        NSString *urlString = [NSString stringWithFormat:@"http://www.google.com"];
        myConnection =[NSURLConnection connectionWithRequest:
                       [NSURLRequest requestWithURL:
                        [NSURL URLWithString:urlString]] 
                                                    delegate:self];
    
    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

    dejo

    Staff Member

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

    Sure, why not.
     

Share This Page