Can someone explain objC syntax to me?

Posted:
in Genius Bar edited January 2014
I've read the Objective C manuals from Apple, the reference book, the book by the Nerd Ranch dude, even looked at "talk to me like I'm a 3-year old" C instructions, but the syntax and use of "objects," "methods," and "Instance variables" in Objective C just are not clicking.



I get the concept: data and its functions/methods living together in such a way that calls or messages are sent to the object, not to the data, and the object activates a method/interaction/function to work the data and return the necessary result to the caller - all the while letting the caller be blind as to the actual data. Sounds great. Wanna use it. Think that it could make my learning of programming better.



Problem is, I can't make sense of the syntax in the examples and sample code. I can type in the examples for the Currency Converter Cocoa app, and it works, but the WHY IT WORKS of it all is just not clicking.



The texts I've read all assume prior knowledge of C, and not just a wee bit - only the "3-year-old" stuff made sense but it is all structural, not objective.



Anyone got an analogy for the cocoa syntax that might help me out?



TIA



- AND a free iPod Podpac case to those who can help this idjit out ($6.99 value!)



Thanks again.

Comments

  • Reply 1 of 6
    thuh freakthuh freak Posts: 2,664member
    well, here goes nothing:

    objc's class' meths are declared kind of screwy (imo), but here goes:

    [code] /*after the @interface*/

    -(returnType) methName parameterList;

    /*later comes the @end*/

    </pre><hr></blockquote>

    return type is the type to be returned (notice its in parenthesis, also id is assumed if u omit a return type). parameterList (if necessary), begins with a colon. then in parethesis, the first param's type. for each other param, you can have an identifier, then the colon, then the type (in parenthesis). here's an example:

    [code] -myMethod: (int)number myCharId : (char) myChar : (int)no2; </pre><hr></blockquote>



    if you have an objc object ( myObject ), and you want to call one of its methods, you do:

    [code] [ myObject methName argList ]; </pre><hr></blockquote>

    argList has a weird syntax. its a colon-delimited list of parameters. and depending on how the meths were declared, each or some args may require an identifier before the colon. example:

    [code] id retval = [myObject myMethod: 0 myCharId:'c' :1]; </pre><hr></blockquote>



    before i continue on, is this the level of learning that you need? or is this too basic or too difficult? i'll gladly give more help, but i was wondering just where the problems are. objc syntax was the biggest hurdle i had when i first hit the lang.



    [edit: fvck ubb]



    [ 10-06-2002: Message edited by: thuh Freak ]</p>
  • Reply 2 of 6
    jccbinjccbin Posts: 476member
    Ok, this is beginning to make sense. What I'm wondering is, where did you learn the syntax? Did I miss the lesson somewhere?



    Thanks very much!



    If you'd like the Podpac for your iPod or for a friend, let me know via email (jccbin at ro3.com)



    any more examples of how this weirdness works?



    THX
  • Reply 3 of 6
    airslufairsluf Posts: 1,861member
  • Reply 4 of 6
    thuh freakthuh freak Posts: 2,664member
    [quote]Originally posted by jccbin:

    <strong>Ok, this is beginning to make sense. What I'm wondering is, where did you learn the syntax? Did I miss the lesson somewhere?



    Thanks very much!



    If you'd like the Podpac for your iPod or for a friend, let me know via email (jccbin at ro3.com)



    any more examples of how this weirdness works?



    THX</strong><hr></blockquote>



    i picked up the syntax from apple's tutorial, and googling endlessly until it made sense to me. i think there's a spot somewhere in the developer docs (/Developer/Documentation/) about the language and the syntax.
  • Reply 5 of 6
    Look for Apple's pdf Object Oriented Programming and The Objective C Language located at Developer/Documentation/Cocoa/ObjectiveC/ObjC.pdf
  • Reply 6 of 6
    jccbinjccbin Posts: 476member
    Thanks for all the help, folks!



    Now... to grow the Killer App (mwwhahahahaha!)



    :-)
Sign In or Register to comment.