您的位置:首页 > 其它

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的格式如下所示:
%@
对象
%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

%ld
 or 
%lx

Cast the value to 
long
.
NSUInteger

%lu
 or 
%lx

Cast the value to 
unsigned long
.
CGFloat

%f
 or 
%g

%f
 works for floats and doubles when formatting; but note the technique described below for scanning.
CFIndex

%ld
 or 
%lx

The same as 
NSInteger
.
pointer
%p
 or 
%zx

%p
 adds 
0x
 to the beginning of the output. If you don't want that, use 
%zx
and
no typecast.
NSLog(@"hello world"); // oc中字符串以@开头

[objc] view
plain copy

 print?





#import <Foundation/Foundation.h>  

int main()  

{  

    NSLog(@"Hello World.");  

    return 0;  

}  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: