# iOS

# Xcode
Cheat-sheet for Xcode
Command + 0 => Left Panel
Command + Option + 0 => Right Panel
Command + R => Run Application
Command + 1, 2, .. => Navigate in Left Panel
Command + Option + 1, 2, .. => Navigate in Right Panel
Command + Shift + y => Debugger
Command + Option + Enter => Open Second Editor
Command + Enter => Close Second Editor
Command + Shift + o => Open file with filename
XCode -> Preferences -> Navigation -> Select ‘Uses Focused Editor’ => Open files in primary as well as second editor
// TODO and MARK comment prefix to enlist tasks and marks under navigation bar
Command + ‘/’ => Comment and uncomment
Control + I => Indents the code
# Objective-C
| 指令 | 含义 | 例子 |
|---|---|---|
| @"chars" | 实现常量 NSSTRING 字符串对象 | NSString *url =@"http://www.kochan-wood.com (opens new window)" |
| @class c1,c2,... | 将c1,c2...声明为类 | @class Point,Rectangle; |
| @defs(class) | 为class返回一个结构变量的列表 | struct Fract { @defs(Fraction);} *fractPtr; fractPtr = (struct Fract *)[[Fraction alloc] init] |
| @dynamic names | 用于names的存取器方法,可动态提供 | @dynamic drawRect; |
| @encode(type) | 将字符串编码类型为type类型 | @encode(int*) |
| @end | 结束接口部分,实现部分或协议部分 | @end |
| @implementation | 开始一个实现部分 | @implementation Fraction |
| @interface | 开始接口部分 | @interface Fraction: Object<Copying> |
| @private | 定义一个或者多个实例变量的作用域 | |
| @protected | 定义一个或者多个实例变量的作用域 | |
| @public | 定义一个或者多个实例变量的作用域 | |
| @property(list)names | 为names声明 list 中的属性 | property(retain,nonatomic)NSSTRING *name; |
| @protocol(protocol) | 指定protocol 创建一个Protocol对象 | @protocol(Copyng){...}if ([myObj onformsTo:(protocol)]) |
| @protocol name | 开始name的协议定义 | @protocol Copying |
| selector(method) | 指定method的SEL(选择)对象 | if([myObj respondsTo:@selector(allocF)]){...} |
| @synchronized(object) | 通过单线程开始一个块的执行,Object已知是一个mutext或semaphore | |
| @synthesize names | 为names生成存取器方法,如果未提供的话 | @synthesize name,email |
| @try | ||
| @catch(exceotion) | ||
| @finally | ||
| @throw |
函数定义
- (return_type) method_name:( argumentType1 )argumentName1
joiningArgument2:( argumentType2 )argumentName2 ...
joiningArgumentn:( argumentTypen )argumentNamen {
body of the function
}
2
3
4
5
# lldb
调用函数
call [[NSProcessInfo processInfo] systemUptime]
print object
po object_a

# swift
struct are value type and class are reference type
argument labels