#import "ViewController.h" #import "stdio.h" @interface ViewController () @end @implementation ViewController //eg:C語言靜態語言 void printHelloStatic() { printf("static"); } void printGoodByeStatic() { printf("Say GoodBye"); } void doSomeThingStatic(int type) { if (type==0) { printHelloStatic(); } else { printGoodByeStatic(); } return; } //eg:C語言動態語言示範 void printHello() { printf("Hello.world!\n"); } void printGoodBye() { printf("Say GoodBye.world!\n"); } void doSomeThing(int type) { void (*fun) (); if (type == 0) { fun = printHello; } else { fun = printGoodBye; } fun(); return ; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //OC消息發送的底層原理 NSString *parameter; id returnValue = [self messageName:parameter]; //編譯器轉換爲 returnValue = objc_msgSend(self,@selector(messageName:),parameter); } -(id)messageName:(NSString *) str { return str; }