标签:style view for microsoft ret sse turn method interface
代码-ViewController.m:
#import "ViewController.h" #import "Dog.h" @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; Dog *dog = [[Dog alloc] init]; [dog performSelector:NSSelectorFromString(@"run")]; [dog performSelector:NSSelectorFromString(@"eat:") withObject:@"bones"]; } @end
代码-Dog.h:
#import <Foundation/Foundation.h> @interface Dog : NSObject @end
代码-Dog.m:
#import "Dog.h" #import <objc/runtime.h> void run(id self, SEL _cmd) { NSLog(@"%s", __FUNCTION__); } void eat(id self, SEL _cmd, NSString *foodName) { NSLog(@"%s %@", __FUNCTION__, foodName); } @implementation Dog + (BOOL)resolveInstanceMethod:(SEL)sel { if (sel == NSSelectorFromString(@"run")) { class_addMethod(self, sel, (IMP)run, "v@:"); return YES; } else if (sel == NSSelectorFromString(@"eat:")) { class_addMethod(self, sel, (IMP)eat, "v@:@"); return YES; } return [super resolveInstanceMethod:sel]; } @end
标签:style view for microsoft ret sse turn method interface
原文地址:http://www.cnblogs.com/xwoder/p/6230997.html