01-Objective-c简介
2014-04-17 16:19
387 查看
一、 OC简介
1.oc 程序执行过程:C语言的基础上,增加了一层最小的面向对象语法
完全兼容C语言
可以在OC代码中混入C语言代码,甚至是C++代码
可以使用OC开发Mac OS X平台和iOS平台的应用程序
实例代码:
1>.完全兼容C语言:
// 在main.m文件里 #include <stdio.h> int main() { printf("OC程序的入口main函数\n"); return 0; } // 终端指令 // 编译: cc -c main.m // 链接: cc main.o // 执行: ./a.out
2>.只含OC代码,不含有C代码:
#import <Foundation/Foundation.h>
// #import 和 #include 的区别 // 跟#include一样,用来拷贝某个文件的内容 // 可以自动防止文件内容被拷贝多次,也就意味着头文件中不用加入下面的预处理指令 // #ifndef _STDIO_H_ // #define _STDIO_H_ // #endif
int main() { NSLog(@"第2个OC程序"); return 0; } // 终端指令 // 编译cc –c main.m // 链接cc main.o –framework Foundation // 运行./a.out
3>.OC和C混用
1) 编写3个文件 main.m one.h one.c ➢ main.m #import "test.h" int main() { test(); return 0; } ➢ test.h void test(); ➢ test.c #include <stdio.h> #include "test.h" void test() { printf("调用了test函数\n"); } 2) 终端指令 ➢ 编译:cc –c main.m test.c ➢ 链接:cc main.o test.o ➢ 运行:./a.out (没有使用Foundation框架的话,就不用-framework Foundation)
相关文章推荐
- Objective-c学习笔记01——简介
- Objective-c学习笔记01——简介
- python科学计算-01程序包和API简介
- (01)Makefile简介
- [yolo2] _01_显卡,GPU和CUDA简介
- OC基础-Objective-c 入门01
- sql_学习笔记01_简介
- Struts2_01_Action简介_HelloWorld
- Masson快速视频制作教程(01) - 简介
- Programming in Objective-C 学习笔记07——Foundation框架基础01
- 23---java正则表达式01(简介)
- javaBean【01】javaBean简介及基本使用
- Activiti基础教程--01(简介、代码生成Activiti的25张表、Activiti配置文件activiti.cfg.xml生成25张表、在Eclipse上安装Activiti插件)
- GitHub 上排名前 100 的 Objective-C 项目简介
- Tornado框架01-高性能简介
- APUE读书笔记-15进程内部通信-01简介
- CMake 学习笔记 01 - CMake 简介
- 大数据笔记01:大数据之Hadoop简介
- 20170726Python01_Python简介和输入输出
- 20170726Python01_Python简介和输入输出