Friday, August 12, 2011

Objective C : Difference between instance method (-) and the class method (+)

Ever since I started reading out the Objective C development. This term has come up many times.

Since, being from a .Net background I am always trying to compare the Objective C to .Net ( which is not what I should be doing but it helps me to grasp the idea quickly).

Hence, after running some research I was able to understand the difference between the class method and instance method in Objective C.

Well, “class method” is what we call static method in C#, while instance methods are only available once we have instantiated the object.

E.g

@interface DeepsClass : NSObject

+ (void)myClassMethod;
- (void)myInstanceMethod;

@end

It can now be used like this : -

[DeepsClass myClassMethod];

DeepsClass *object = [[DeepsClass alloc] init];
[object myInstanceMethod];

No comments:

Post a Comment