Parameters and Properties


#1

There is this one thing I do not understand regarding properties, say I have an instance method, that returns void and has two parameters

with properties you just declare an Ivar with the same name, does this become then like a sort of parameter, that you can set, and instead of having two parameters you can have two different properties instead, to set your arguments, like you do with parameters?

int someName; @property int someName;

In this case, the only time you would not use @properties, is if you need the instance method to perform some special functions in it´s implementation like:

-(float)valueInDollars{ return [self numberOfShares] * [self currentSharePrice]; }

Am I right?


#2

I don’t quite understand the question, but let me correct your syntax. A method that takes two parameters looks like this:

If you will clarify your question, I’ll do my best to answer it.


#3

Ok, cool! the question is about the difference between properties and instance method, as I understand it - a instance method that only has one parameter and no special code associated with it you might aswell use @property to set it accessors. But what if it needs to have two parameters like this, then you would set the setters & getters manually right? or rethink it and make 2 seperate properties instead of one instance method with two parameters.


#4

Instance methods can have any number of arguments. I think you are talking about accessor methods (instance methods for getting and setting the value of an instance variable). A property is a shorthand way to declare a pair of accessor methods. The setter method does, indeed, take one argument. (The getter takes no arguments.)

Yes, if you wanted to set two instance variables with one method, you could declare and implement that method separately. For example, if it were something dealing with fonts, you might set the fontSize and hasUnderline instance variables with one method:

[textArea setFontSize:16 hasUnderline:YES];