ios的一些知识块摘录

1.每个项目中至少有一个targer,targer使用项目中的文件来构建一个特定的产品,Xcode构建并运行的是目标,不是项目(project)。(A project always has at least one target. A target uses the files in the project to build a particular product. When you build and run, you build and run the target, not the project.)

2.协议方法:协议方法分为可选择(optional)和(required),默认为required。如果为可选择方法,再向delegate发送消息之前,会调用respondsToSelector:来确定delegate是否实现了这个方法,例如:

- (void)finishedFindingLocation:(CLLocation *)newLocation
{
// locationManager:didUpdateToLocation:fromLocation:
// is an optional method, so we check first.
SEL updateMethod = @selector(locationManager:didUpdateToLocation:fromLocation:);
if ([[self delegate] respondsToSelector:updateMethod]) {
// If the method is implemented, then we send the message.
[[self delegate] locationManager:self
didUpdateToLocation:newLocation
fromLocation:oldLocation];
}
}

如果协议方法是required的,消息就会不经过检查是否被实现而直接被发送。这样的话,如果delegate不实现协议方法,运行的时候就会抛出一个异常说:an unrecognized selector,为了防止这种情况,编译器会坚持delegate实现required协议方法,为了使编译器能够知道并且检查这些方法,代理对象一定要直接声明它遵守了这个协议,所以要在头文件中声明如:@interface WhereamiAppDelegate : NSObject<UIApplicationDelegate, CLLocationManagerDelegate>。

3.类实例不会保留它的委托对象,(Delegates are never retained by their delegating objects)。因为会造成互相拥有,产生retain循环的问题。有些对象是不需要释放内存的比如:WhereamiAppDelegate,直到应用程序关闭。

4.构建阶段(Build phases),编译器(Compiler),连接器(Linker)

各个构建阶段包括:编译源代码(Compile Sources),连接二进制文件和库(Link Binary With Libraries),拷贝程序包资源(Copy Bundle Resources)。

5.编译源代码分为两个阶段:预处理和编译。预处理的作用是为每个实现文件创建一个中间文件(intermediate file)中间文件和实现文件一样,都是oc代码,但中间文件的体积可能会更大,预处理器处理完实现文件中的全部预处理指令后,会生成一个中间文件。预处理指令是带有前缀#的语句如:#import。预处理器在处理#import语句时,会将该语句换成导入文件的内容。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值