Monday, 24 July 2017

Class level method







A class method is called on the class the method belongs to, not an instance of it. This is possible because Objective-C classes are also objects. To denote a method as a class method, change the - to a +:
+ (void)hello {
  NSLog(@"Hello World");
}

Example -
--------------------------------------------------------------------------

#import <Foundation/Foundation.h>

@interface Car:NSObject
+ (void)speed;
@end
@implementation Car
+ (void)speed
{
    NSLog(@"Current speed : 60");
    }
@end
int main()
{
    [[Car class] performSelector:@selector(speed)];
    return 0;
   
    }
-----------------------------------------------------------------------------
















22

No comments:

Post a Comment