您的位置:首页 > 移动开发 > Objective-C

系统学习Objective-C<基础>

2012-04-19 11:23 441 查看
#import <Foundation/Foundation.h>
BOOL areInstDifferent(int thing1, int thing2);
NSString *boolString(BOOL yesNO);
BOOL areInstDifferent(int thing1, int thing2)
{
if(thing1 == thing2)
{
return (NO);
}
else
{
return (YES);
}
}

NSString *boolString(BOOL yesNO)
{
if(yesNO == NO)
{
return (@"NO");
}
else
{
return (@"YES");
}
}

int main(int argc, const char * argv[])
{
@autoreleasepool
{
BOOL areTheyDifferent;
areTheyDifferent = areIntsDifferent(5, 5);
NSLog(@"are %d and %d different? %@", 5, 5, boolString(areTheyDifferent));
areTheyDifferent = areIntsDifferent(23, 42);
NSLog(@"are %d and %d different? %@", 23, 42, boolString(areTheyDifferent));
}
return 0;
}


以上简单的代码就是对Objective-C的很好的解释,跟C语言区别不是很大,但也有不同,值得注意的就是:#import <Foundation/Foundation.h>、NSLog(@"");、BOOL的使用,要特别注意以上三个与C语言中的区别,不要掉进BOOL的陷阱中。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: