没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/octet-stream](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![CHM](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![h](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/release/download_crawler_static/4723237/bg1.jpg)
Objective-C 语法总结
Document Author
Doho
Contact
52doho [at] 163 [dot] com
Version
第一版
Data created
2010-5-14
Contents
说明 ................................................................................................................................................. 3
XCode、Objective-C、Cocoa .................................................................................................. 3
Common Filename Extensions ................................................................................................ 4
数据类型 ......................................................................................................................................... 4
int ................................................................................................................................................ 4
装箱 ............................................................................................................................................. 5
复合数据类型 ................................................................................................................................. 5
一维数组 ..................................................................................................................................... 5
可变长度数组 ............................................................................................................................. 5
多维数组 ..................................................................................................................................... 6
结构体 ......................................................................................................................................... 6
联合体 ......................................................................................................................................... 7
指针 ............................................................................................................................................. 8
枚举 ............................................................................................................................................. 8
typedef ........................................................................................................................................ 8
类型修饰符 ................................................................................................................................. 8
操作符优先级 ............................................................................................................................. 9
成员变量可访问性 (@private, @protected, @public, @package) ........................................... 9
id ............................................................................................................................................... 10
![](https://csdnimg.cn/release/download_crawler_static/4723237/bg2.jpg)
NSString .................................................................................................................................. 10
NSArray, NSMutableArray ................................................................................................. 10
NSSet, NSMutableSet .......................................................................................................... 10
NSDictionary, NSMutableDictionary ............................................................................... 11
BOOL ........................................................................................................................................ 11
nil, NULL .................................................................................................................................. 12
#import ....................................................................................................................................... 12
@interface .................................................................................................................................. 13
@implementation .................................................................................................................... 13
方法调用 (消息) ........................................................................................................................... 14
多重参数的方法 ........................................................................................................................... 15
方法可访问性 (public, private, protected) ........................................................................... 17
属性 ............................................................................................................................................... 18
Technique 1 ........................................................................................................................... 18
Technique 2 ........................................................................................................................... 18
Technique 3 ........................................................................................................................... 19
@property NSInteger luckyNumber;构造函数 ....................................................................... 19
对象刜始化 ................................................................................................................................... 21
内存管理 (retain, release, autorelease, dealloc, Autorelease pools) ............................ 22
对象拥有者 ........................................................................................................................... 24
线程 ............................................................................................................................................... 24
Run Loop ................................................................................................................................ 26
Structure of a run loop and its sources ................................................................................. 26
接口 @Protocal ............................................................................................................................. 26
formal .................................................................................................................................... 26
informal (category) ................................................................................................................ 26
@Category ..................................................................................................................................... 27
![](https://csdnimg.cn/release/download_crawler_static/4723237/bg3.jpg)
Dynamic typing .............................................................................................................................. 27
target-action .................................................................................................................................. 29
Forwarding .................................................................................................................................... 29
Unit Tests ....................................................................................................................................... 29
线程 ............................................................................................................................................... 29
反射 ............................................................................................................................................... 29
条件编译 ....................................................................................................................................... 29
MVC ............................................................................................................................................... 30
KVC (Key Value Coding) ................................................................................................................. 30
KVO (Key Value Observing) ........................................................................................................... 30
Target-Action ................................................................................................................................. 31
Design Patterns ............................................................................................................................. 31
说明
作者本人做过两个 iPhone 项目,过程当中对 iPhone 开发语言 Objective-C 有一些理解
以及开发经验,并把这些记录下来,形成此文档(当前为刜稿,难免有些晦涩:),希望跟
有意做 iPhone 开发的朋友分享。有一些内容是参考网页、Standford 大学课程、Apple
官方视频。此稿为刜稿,希望大家评阅乊后有意见就给以我反馈(email),我会整合大
家意见再次整理并发布最新的文档,谢谢!
XCode、Objective-C、Cocoa
XCode:你可以把它看成是一个开发环境,就好像 Visual Studio 戒者 Netbeans 戒者 SharpDevelop 一样
的玩意。你可以将 Interface Builder 认为是 Visual Studio 中用来画界面的那部分功能单独提出来的程序。
Objective-C:这是一种语言,就好像 c++是一种语言,Java 是一种语言,c#是一种语言,莺歌历史也是一
种语言一样。
Cocoa:是一大堆函数库,就好像 MFC、.NET、Swing 这类玩意,人家已经写好了一堆现成的东西,你只要
知道怎么用就可以了。
![](https://csdnimg.cn/release/download_crawler_static/4723237/bg4.jpg)
Common Filename Extensions
Extension
Meaning
.c
C language source file
.cc, .cpp
C++ language source file
.h
Header file
.m
Objective-C source file
.mm
Objective-C++ source file
.pl
Perl source file
.o
Object (compiled) file
数据类型
int
8 迚制,base 8:0177 = 127 (1 × 64 + 7 × 8 + 7).
NSLog (“base 8: %o\n”, num);
16 迚制,base 16, hexidecimal:
NSLog (“Color is %x\n”, rgbColor); //戒者:%#x
Type
Meaning
int
Integer value; that is, a value that contains no decimal point; guaranteed
to contain at least 16 bits of accuracy
short int
Integer value of reduced accuracy; takes half as much memory as an
int on some machines; guaranteed to contain at least 16 bits of accuracy
long int
Integer value of extended accuracy; guaranteed to contain at least 32
bits of accuracy
long long int
Integer value of extra-extended accuracy; guaranteed to contain at least
64 bits of accuracy
unsigned int
Positive integer value; can store positive values up to twice as large as
an int; guaranteed to contain at least 16 bits of accuracy
float
Floating-point value; that is, a value that can contain decimal places;
guaranteed to contain at least six digits of precision
double
Extended accuracy floating-point value; guaranteed to contain at least
10 digits of precision
![](https://csdnimg.cn/release/download_crawler_static/4723237/bg5.jpg)
long double
Extra-extended accuracy floating-point value; guaranteed to contain at
least 10 digits of precision
char
Single character value; on some systems, sign extension can occur
when used in an expression
unsigned char
Same as char, except it ensures that sign extension will not occur as a
result of integral promotion
signed char
Same as char, except it ensures that sign extension will occur as a result
of integral promotion
_Bool
Boolean type; large enough to store the value 0 or 1
float _Complex
Complex number,引用:#import <complex.h>
double
_Complex
Extended accuracy complex number,double _Complex c1 = 5 + 10.5 ∗ I;
long double
_Complex
Extra-extended accuracy complex number
void No type;
used to ensure that a function or method that does not return a
value is not used as if it does return one, or to explicitly discard the results
of an expression; also used as a generic pointer type (void *)
装箱
NSNumber *integer = [NSNumber numberWithInt:8];
int x = [integer intValue];
复合数据类型
一维数组
type name[n] = { initExpression, initExpression, .. };
char today[] = “Monday”; // ‘M’,‘o’,'n', 'd', 'a', 'y', and '\0'
char today[6] = “Monday”;// 'M', 'o', 'n', 'd', 'a', and 'y'
int x = 1233;
int a[] = { [9] = x + 1, [2] = 3, [1] = 2, [0] = 1 };//10 个元素的数组
可变长度数组
int makeVals (int n)
{
int valArray[n];//运行中动态分配
...
剩余30页未读,继续阅读
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
- wangqiang6_20112012-12-18object c 的电子书, 太少了, 本书对于入门还是有点帮助的
- kevincai1002014-08-08不错。。。。初学者可以看看
- dumuzhou20102015-04-03对于入门有帮助
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
glsoft2006
- 粉丝: 53
- 资源: 15
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)