Implementing protocols

Discussion in 'iOS Programming' started by iphonequestions, Mar 21, 2010.

  1. iphonequestions macrumors newbie

    Joined:
    Mar 21, 2010
    #1
    hey guys,

    I am just creating an app at the moment, im a bit new at this, and i have just one question, i think i can get the rest working. Im not sure if its a really easy question to answer but ill give it a go anyway.

    I need to implement a protocol and i have no idea what to write, can anyone tell me what it would look like to implement a protocol for this error im getting?

    warning: class 'FirstViewController' does not implement the 'SubstitutableViewController' protocol

    I looked up the documentation and all i seen was

    But what should this look like given the error im getting?

    Thank you for any help.
     
  2. skunkworker macrumors regular

    Joined:
    Sep 9, 2007
    #2
    Well for one you should post some more code explaining it in further detail. secondly the FirstViewController is not implementing the methods the protocol outlined.
    Example:
    if myProtocol has two methods, add:(int)number and subtract:(int)number, then the class that is implementing it must have those methods, unless they are @optional.
     
  3. chbeer macrumors member

    chbeer

    Joined:
    Sep 22, 2008
    Location:
    Berlin
    #3
    The error says, that you need to specify the protocol on the interface that implements it, like so:

    Code:
    @interface Classname <Protocol,Protocol2> {
    ...
    }
    ...
    @end
    HTH,
    Christian
     
  4. iphonequestions thread starter macrumors newbie

    Joined:
    Mar 21, 2010
    #4


    Ok, so would i put something like this in my code:
    Or is this completely wrong? I put this in and it still says the same thing..
     
  5. jhurley macrumors newbie

    Joined:
    Feb 2, 2010
    #5
    more like,
    Code:
    @interface FirstViewController<SubstitutableViewController> {
    ...
    }
    ...
    @end
    
     
  6. iphonequestions thread starter macrumors newbie

    Joined:
    Mar 21, 2010
    #6
    Thanks for the reply!!

    But, what goes in the "..." areas?

    When i wrote something like that i got an error saying "error: expected identifier or '(' before '{' token"?!
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    Asking such a question indicates you don't really have a handle on the basics of Objective-C. I would suggest you step away from the real coding for a while and go learn those basics.
     
  8. iphonequestions thread starter macrumors newbie

    Joined:
    Mar 21, 2010
    #8
    I think that's a valid question for a beginner!!! I am trying to learn, as i said i read the documentation, but it DOES NOT say what to put in there... Just an empty 3 lines. It's a simple question (probably why your saying that) but that doesn't mean you can't answer it?!


    Please, enlighten me as to what the basics are of this problem?

     
  9. jhurley macrumors newbie

    Joined:
    Feb 2, 2010
    #9
    in the @interface ClassName{ ... } spot you're putting your class member variables. Between the } and @end you're assigning properties and prototyping member functions.
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    My apologies if I came across harsh but I felt it needed to be said. What documentation have you read? The more info you can provide us of what you know, have read, etc. the better we can try to tailor our answers to your experience level.

    jhurley has answered this now. Hope you understand the answer.
     
  11. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #11
    I'd say the documentation is pretty clear an simple on this.

    Core Cocoa Protocols

    The definitive article

    Each protocol will require a different number of lines with different content. It is important you understand what's going on in a general way, not specific to this protocol.

    Before writing any code you should have read and fully understood all of the Core Cocoa documentation at the very least (I personally think this is probably tool little).
     

Share This Page