ios的一些知识块摘录

来源:互联网 发布:上海数龙网络官网 编辑:程序博客网 时间:2024/05/15 03:52

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
原创粉丝点击