What does this small piece of code block means ?

Discussion in 'iOS Programming' started by Vishwas Gagrani, Oct 3, 2012.

  1. Vishwas Gagrani, Oct 3, 2012
    Last edited by a moderator: Oct 3, 2012

    Vishwas Gagrani macrumors newbie

    Joined:
    Sep 26, 2012
    #1
    Code:
    -(NSString*)myField{
    return myField; 
    }
    What's what here ?

    NSString seems to be type of myField.

    But where is the function name ? What's the myField doing after (NSString*). What's the * after NSString. Is * similar to "Pass by Value", "Pass by Reference" as in C,C++?


    thanks
    V.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    This can all be answered if you know the fundamentals of Objective-C. What resources are you using to educate yourself on the basics?
     
  3. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #3
    It's a method (not a function.) Its return type is a pointer to an NSString. The method name is myField, and it returns the instance variable, also named myField. This method is a getter for the instance variable myField.

    Having a getter like this isn't very common anymore with properties, which can automagically create getters and setters for you, having been introduced in Obj-C 2.0.
     
  4. Vishwas Gagrani thread starter macrumors newbie

    Joined:
    Sep 26, 2012
    #4
    Thanks ArtOfWarfare

    It's an ebook edition of Head First.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Care to be more specific? Courtesy requests that you provide title, author, edition, and chapter and page number, if appropriate.
     

Share This Page