打开Xcode,选择Command Line Tool,类型选择Foundation;
其中.m为源文件;
例1:
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { NSLog(@"Hello, World!"); return 0; }
例2:BOOL与NSString的使用
#import <Foundation/Foundation.h> BOOL isDiff(int a, int b) { if(a==b) { return (NO); } else { return (YES); } } NSString* boolStr(BOOL b) { if (b == NO) { return (@"NO"); } else { return (@"YES"); } } int main(int argc, const char * argv[]) { BOOL bRet; bRet = isDiff(5, 5);//NO NSLog(@"are %d and %d different?:%@", 5, 5, boolStr(bRet));//NO bRet = isDiff(23, 42); NSLog(@"are %d and %d different?:%@", 23, 42, boolStr(bRet)); return 0; }