The value of NSValueWithPointer / pointerValue works equally well.
you just need to know that you cannot serialize the array (i.e. write it to a file), if you want to do this, use the NSStringFromSelector approach.
These are all valid ways to place a selector in an NSValue object:
id selWrapper1 = [NSValue valueWithPointer:_cmd]; id selWrapper2 = [NSValue valueWithPointer:@selector(viewDidLoad)]; id selWrapper3 = [NSValue valueWithPointer:@selector(setObject:forKey:)]; NSString *myProperty = @"frame"; NSString *propertySetter = [NSString stringWithFormat:@"set%@%@:", [[myProperty substringToIndex:1]uppercaseString], [myProperty substringFromIndex:1]]; id selWrapper4 = [NSValue valueWithPointer:NSSelectorFromString(propertySetter)]; NSArray *array = [NSArray arrayWithObjects: selWrapper1, selWrapper2, selWrapper3, selWrapper4, nil]; SEL theCmd1 = [[array objectAtIndex:0] pointerValue]; SEL theCmd2 = [[array objectAtIndex:1] pointerValue]; SEL theCmd3 = [[array objectAtIndex:2] pointerValue]; SEL theCmd4 = [[array objectAtIndex:3] pointerValue];
source share