0

Possible Duplicate:
What do the plus and minus signs mean in Objective C next to a method?

I want to know the difference between the methods with - symbol and with +symbaol.

Ex.-(NSMutableArray *)getContactsList; +(NSMutableArray *)getContactsList;

Thanks Praveena.

Community
  • 1
  • 1
praveena
  • 733
  • 2
  • 11
  • 22
  • 2
    Same as [What do the plus and minus signs mean in Objective C next to a method? ](http://stackoverflow.com/questions/2097294/what-do-the-plus-and-minus-signs-mean-in-objective-c-next-to-a-method). – Matthew Flaschen Dec 28 '10 at 07:41
  • one is instance method and other is class method – GhostRider Dec 28 '10 at 07:42

2 Answers2

2

The difference between the two methods is;

The method which start with "-" is an instance method. you can call that method using the object of the specific class.

Ex:

A *a = [[A alloc] init];
array = [a getContactsList];

And The method which start with "+" is a Class method. you can call that method using class name.

Ex:

array = [A getContactsList];

That is the main difference.

And one more thing in the Class method you can use the Static variables only, instance variables.

Regards,

Satya.

Satya
  • 3,320
  • 1
  • 20
  • 19
  • 1
    Class methods can use statics or globals. I'm assuming "private" and "normal" means instance variables? If so, then yes, but at least call 'em by their rightful name! – bbum Dec 28 '10 at 08:55
-1

The method with + is static method, which returns you a retained object, with an autorealease, it means you are not the owner of the object.

Oleg Danu
  • 4,149
  • 4
  • 29
  • 47
  • Objective-C does not have "static" methods; it has class methods. Class methods are not guaranteed to return an autoreleased object (see `+new`). – bbum Dec 28 '10 at 08:46