OC基础之一-______HelloWorld
2016-01-24 23:07
274 查看
.h :头文件。头文件包含类,类型,函数和常数的声明。
.m :源代码文件。这是典型的源代码文件扩展名,可以包含Objective-C和C代码。
.mm :源代码文件。带有这种扩展名的源代码文件,除了可以包含Objective-C和C代码以外还可以包含C++代码。仅在你的Objective-C代码中确实需要使用C++类或者特性的时候才用这种扩展名
当你需要在源代码中包含头文件的时候,你可以使用标准的#include编译选项,但是Objective-C提供了更好的方法。#import选项和#include选项完全相同,只是它可以确保相同的文件只会被包含一次。
#import <Foundation/Foundation.h>
OC推荐用#import包含头文件,用c语言方式的#include也可以
Foundation框架
包含文件 跟c一样, <>系统的 ""用户的
关键字
@interface,@implementation,@end
@public、@protected、@private,@selector
@try、@catch、@throw、@finally
@protocol,@class
self、id、super、_cmd、_block、_strong、_weak (不以@开头)
// OC 2.0中引入的新关键字有
@property,@synthesize
@optional,@required,@dynamic
程序入口也是一个main函数
NSLog函数 即c的形式定义的
是一个日志输出函数,它可以将传入的OC字符串参数输出到控制台上
输出完毕后自动换行
支持格式符:
* %f表示接收浮点型数据,%.2f表示保留2位小数
NSLog的格式如下所示:
NSLog(@"hello world"); // oc中字符串以@开头
[objc] view
plain copy
print?
#import <Foundation/Foundation.h>
int main()
{
NSLog(@"Hello World.");
return 0;
}
.m :源代码文件。这是典型的源代码文件扩展名,可以包含Objective-C和C代码。
.mm :源代码文件。带有这种扩展名的源代码文件,除了可以包含Objective-C和C代码以外还可以包含C++代码。仅在你的Objective-C代码中确实需要使用C++类或者特性的时候才用这种扩展名
当你需要在源代码中包含头文件的时候,你可以使用标准的#include编译选项,但是Objective-C提供了更好的方法。#import选项和#include选项完全相同,只是它可以确保相同的文件只会被包含一次。
#import <Foundation/Foundation.h>
OC推荐用#import包含头文件,用c语言方式的#include也可以
Foundation框架
包含文件 跟c一样, <>系统的 ""用户的
关键字
@interface,@implementation,@end
@public、@protected、@private,@selector
@try、@catch、@throw、@finally
@protocol,@class
self、id、super、_cmd、_block、_strong、_weak (不以@开头)
// OC 2.0中引入的新关键字有
@property,@synthesize
@optional,@required,@dynamic
程序入口也是一个main函数
NSLog函数 即c的形式定义的
是一个日志输出函数,它可以将传入的OC字符串参数输出到控制台上
输出完毕后自动换行
支持格式符:
* %f表示接收浮点型数据,%.2f表示保留2位小数
NSLog的格式如下所示:
%@ | 对象 |
%d, %i | 整数 |
%u,%z | 无符整形 |
%f | 浮点/双字 |
%x, %X | 十六进制整数 |
%o | 八进制整数 |
%zu | size_t |
%p | 指针 |
%e | 浮点/双字 (科学计算) |
%g | 浮点/双字 |
%s | C字符串 |
%.*s | Pascal字符串 |
%c | 字符 |
%C | unichar |
%lld | 64位长整数(long long) |
%llu | 无符64位长整数 |
%Lf | 64位双字 |
%hhd | BOOL布尔类型 |
NSInteger | %ldor %lx | Cast the value to long. |
NSUInteger | %luor %lx | Cast the value to unsigned long. |
CGFloat | %for %g | %fworks for floats and doubles when formatting; but note the technique described below for scanning. |
CFIndex | %ldor %lx | The same as NSInteger. |
pointer | %por %zx | %padds 0xto the beginning of the output. If you don't want that, use %zxand no typecast. |
[objc] view
plain copy
print?
#import <Foundation/Foundation.h>
int main()
{
NSLog(@"Hello World.");
return 0;
}
相关文章推荐
- [转]Unity中使用ulua的个人经验总结
- Codeforces Round #340 (Div. 2) A. Elephant 水题
- 重温C语言小感
- CSS块级元素、内联元素概念
- 在django1.7.5中访问静态文件(js css)
- Python 各种测试框架简介(二):unittest
- 模板的实例化和具体化
- xilinx FPGA 配置原理
- StrictMode 严苛模式 .
- 一个自用的xeLatex中英文模板
- 1.2.3 Name That Number
- swift自学笔记(三)(泛型、守护、属性观察、扩展、单例)
- EasyPR--一个开源的中文车牌识别系统
- iOS开发实践之JSON
- Ubutun纯净安装使用“搜狗拼音输入法”
- leetcode300---Longest Increasing Subsequence(最长递增子序列)
- OpenGL的Draw函数
- 从零开始写一个Tomcat(贰)--建立动态服务器
- 手机显示电量原理
- Codeforces Round #340 (Div. 2) D. Polyline 水题