1

I'm new to objective C, I'm following "Objective C 5th Edition Stephen Kochan and I don't have anyone to ask my doubts to. I'm confused with this question:

Q. Is it necessary to use "-" or "+" before every property or method declaration in Interface? What will happen if I don't use "-" or "+" before every property or method declaration in Interface?

3
  • 2
    Please only ask one question per question - it reduces the problems when different people answer different questions that you have - no one answer answers the entire question you have (this doesn't fit the Stack Exchange format well). Please consider editing the question so that it only has one question in it.
    – user40980
    Oct 13, 2013 at 1:26
  • 2
    Do you have an obj-c compiler? Why not try it yourself?
    – Lucina
    Oct 13, 2013 at 1:33
  • @MichaelT I would have done that but I thought it will be easy for both myself and the one who will answer me. But I have edited the question now.
    – babu rao
    Oct 13, 2013 at 6:59

2 Answers 2

3

A "+" before a method indicates a class method. These methods can only operate on class variables (variables common to all objects of a class), and can be called before an object of this class has been instantiated.

A "-" indicates an instance method. These methods can operate on class and instance variables. They are called on an instance of an object.

3

Yes it is necessary to declare the method type specifier, if you don't declare those method types, you will receive a red warning telling you that you need to specify the method type.

Also it is recommended to assign the method type specifier in order to see which methods are class methods, and which ones are instance methods.

The "-" sign indicates an instance method.

The "+" sign indicates a class method.

1
  • Is this officially called a type specifier? I thought it was a scope.
    – Ky -
    Apr 20, 2016 at 21:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.