2

Possible Duplicate:
Are selectors in objective - c just another way to send a message to an object?

I understand how the @selector syntax works, but can't figure out when they are useful. For example let's say I have class Person;

Person.h

@interface Person : NSObject

-(void)printPersonName;
@end

Person.m

@implementation Person

-(id)init
{
    if (self = [super init]) {
        [self performSelector:@selector(printPersonName)];
        [self printPersonName];
    }
    return self;
}

-(void)printPersonName
{
    NSLog(@"My name is Steve");
}
@end

This snippet of code do the same thing

[self performSelector:@selector(printPersonName)];
[self printPersonName];

When is @selector useful?

Community
  • 1
  • 1
OhDoh
  • 433
  • 2
  • 9
  • 22

0 Answers0