系统学习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的陷阱中。
相关文章推荐
- html系统学习之一<基础知识,标签,元素>
- 发生系统错误 1275.此驱动程序被阻止加载 寒江孤钓<<windows 内核安全编程>> 学习笔记
- linux基础学习<二>
- JavaScript基础学习<五>对象参数引用
- Java系列学习笔记------Java语言基础<2>
- JAVA基础学习--网络编程<二>
- java 从零开始,学习笔记之基础入门<JDBC>(二十四)
- LensKit<开源推荐系统框架Java>学习笔记
- html系统学习之三 <表格,列表,表单>
- 黑马程序员java学习<基础加强>—泛型
- <Linux 私房菜>基础学习篇学习记录(1)基础命令
- opengl基础学习<一>
- <<Python基础教程>>学习笔记 | 第10章 | 充电时刻
- java 从零开始,学习笔记之基础入门<抽象类_接口_多态>(十三)
- Git学习之基础<2>
- javaweb基础学习(一)<ServletConfig与ServletContext对象详解>
- linux系统学习第十六天-<<工程师技术>> PXE网络自动装机
- <<Python基础教程>>学习笔记 | 第08章 | 异常
- [原]java专业程序代写(qq:928900200),学习笔记之基础入门<JDBC>(二十四)
- SQL Server XML基础学习之<5>--XQuery(query)