#import <Foundation/Foundation.h>
#import <objc/message.h>
#import "Person.h"
Person *person;
void callback(int cmd) {
person= [[Person alloc]init];
person.name = @"张三";
int result = ((int(*)(id,SEL,int))objc_msgSend)(person,@selector(run:),cmd);
NSLog(@"返回结果:%d",result);
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
while (YES) {
int input = 0;
NSLog(@"请输入命令(输入0退出):");
scanf("%d",&input);
if (input == 0) {
break;
}
callback(input);
}
NSLog(@"Hello, World!");
}
return 0;
}
#import <Foundation/Foundation.h>
@interface Person : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, assign) int age;
- (void)run;
- (int)run:(NSInteger)age;
@end
#import "Person.h"
@implementation Person
- (void)run {
NSLog(@"%@ %d",self.name,self.age);
}
-(int)run:(NSInteger)age {
self.age = age;
NSLog(@"%@ %d",self.name,self.age);
return 1;
}
@end