系统学习Objective-C<基础>
1 #import <Foundation/Foundation.h> 2 BOOL areInstDifferent(int thing1, int thing2); 3 NSString *boolString(BOOL yesNO); 4 BOOL areInstDifferent(int thing1, int thing2) 5 { 6 if(thing1 == thing2) 7 { 8 return (NO); 9 } 10 else 11 { 12 return (YES); 13 } 14 } 15 16 NSString *boolString(BOOL yesNO) 17 { 18 if(yesNO == NO) 19 { 20 return (@"NO"); 21 } 22 else 23 { 24 return (@"YES"); 25 } 26 } 27 28 int main(int argc, const char * argv[]) 29 { 30 @autoreleasepool 31 { 32 BOOL areTheyDifferent; 33 areTheyDifferent = areIntsDifferent(5, 5); 34 NSLog(@"are %d and %d different? %@", 5, 5, boolString(areTheyDifferent)); 35 areTheyDifferent = areIntsDifferent(23, 42); 36 NSLog(@"are %d and %d different? %@", 23, 42, boolString(areTheyDifferent)); 37 } 38 return 0; 39 }
以上简单的代码就是对Objective-C的很好的解释,跟C语言区别不是很大,但也有不同,值得注意的就是:#import <Foundation/Foundation.h>、NSLog(@"");、BOOL的使用,要特别注意以上三个与C语言中的区别,不要掉进BOOL的陷阱中。
吾屋无污,吴捂屋污,诬吾污屋,吾晤吴污,吾无物污,吴侮污吾,吾忤吴屋,悟吴诬吾,污屋吴污,吴侮吾污,吾勿武侮,吾唔吴误,诬侮污吾,吾屋悟忤.