iOS What does this small piece of code block means ?

Vishwas Gagrani

macrumors newbie
Original poster
Sep 26, 2012
21
0
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.
 
Last edited by a moderator:

dejo

Moderator
Staff member
Sep 2, 2004
15,981
450
The Centennial State
This can all be answered if you know the fundamentals of Objective-C. What resources are you using to educate yourself on the basics?
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
8,703
4,330
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.