RosettaCodeData/Task/Send-an-unknown-method-call/Objective-C/send-an-unknown-method-call.m

23 lines
407 B
Mathematica
Raw Permalink Normal View History

2013-04-10 23:57:08 -07:00
#import <Foundation/Foundation.h>
2014-04-02 16:56:35 +00:00
@interface Example : NSObject
2013-04-10 23:57:08 -07:00
- (NSNumber *)foo;
@end
@implementation Example
- (NSNumber *)foo {
2014-04-02 16:56:35 +00:00
return @42;
2013-04-10 23:57:08 -07:00
}
@end
int main (int argc, const char *argv[]) {
2014-04-02 16:56:35 +00:00
@autoreleasepool {
2013-04-10 23:57:08 -07:00
2014-04-02 16:56:35 +00:00
id example = [[Example alloc] init];
SEL selector = @selector(foo); // or = NSSelectorFromString(@"foo");
NSLog(@"%@", [example performSelector:selector]);
2013-04-10 23:57:08 -07:00
2014-04-02 16:56:35 +00:00
}
2013-04-10 23:57:08 -07:00
return 0;
}