欢迎访问我的独立博客

【Objective-C】系列01:入门训练

打开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;
}
posted @ 2012-11-09 01:44  github.com/starRTC  阅读(303)  评论(0编辑  收藏  举报