摘要: Chapter 12 : 归档1. 归档 :-> 定义: 用某种格式来保存一个或多个对象,以便以后还原这些对象的过程。其中包括将多个对象写入文件,以便以后读回该对象。-> 方法:(1)属性列表; (2)带键值的编码。2. 属性列表:若对象是NSString, NSDictionary, NSArray, NSData, NSNumber对象时,可以使用writeToFile:atomically:方法将数据写入到文件中,是以属性列表的形式写到文件中的。PS : 参数atomically为YES, 表示先将数据写到临时备份文件中,一旦成功,再转移到文件中。示例代码:#import & 阅读全文
posted @ 2012-09-28 17:48 BankFish 阅读(494) 评论(0) 推荐(0) 编辑
摘要: Chapter 11 : 复制对象1. 回顾继承部分的代码如下: 1 // XYPoint类声明 2 // XYPoint.h文件 3 4 #import <Foundation/Foundation.h> 5 6 @interface XYPoint : NSObject 7 { 8 int x; 9 int y;10 }11 12 @property int x;13 @property int y;14 15 - (void)setX:(int)xVal andY:(int)yVal;16 17 @end 1 // XYPoint类定义 2 // XYPoint.m文... 阅读全文
posted @ 2012-09-28 16:45 BankFish 阅读(555) 评论(0) 推荐(0) 编辑
摘要: Chapter 10 : 属性列表PS : Objective-C可使用与C绑定的所有工具,例如标准C库函数。可使用malloc()和free()函数处理动态内存管理问题,或者使用open(), read(), write(), fopen()和fread函数处理文件。-> 属性列表类包括NSArray, NSDictionary, NSString, NSNumber, NSDate和NSData。1. NSDate :用于处理日期和时间的基础类,是一个自动释放对象。示例如下:1 // 获取当前日期和时间2 NSDate *date = [NSDate date];3 NSLog(@& 阅读全文
posted @ 2012-09-28 15:34 BankFish 阅读(465) 评论(0) 推荐(0) 编辑
摘要: Chapter 9 : 分类和协议1. 协议(protocol) : 其声明类于类接口的声明,不同的是,协议没有父类,且不能定义成员变量。2. 协议(protocol)声明如下:1 @protocol MyProtocol2 3 - (void)myProtocolMethod;4 5 @end-> 协议(protocol)是多个类共享的一个方法列表(Methods List), 协议(protocol)中列出的方法没有相应的实现。如果一个类采用MyProtocol协议,则必须实现名为myProtocolMethod的方法。3. 协议(protocol)的使用: 通过在@interfa. 阅读全文
posted @ 2012-09-28 12:02 BankFish 阅读(266) 评论(0) 推荐(0) 编辑
摘要: Chapter 9 : 分类和协议1. 分类(Category):-> 作用:可以以模块的方式向现有的类添加方法,将类的定义模块化到相关方法的组或分类中。-> 意义:提供了扩展现有类定义的简便方式,并且不必访问类的源代码,也无需创建子类。2. 示例代码: 1 // Fraction类声明 2 // Fraction.h文件 3 4 #import <Foundation/Foundation.h> 5 6 @interface Fraction : NSObject 7 { 8 int numerator; 9 int denominator;10 }11 12 @pr 阅读全文
posted @ 2012-09-28 11:35 BankFish 阅读(204) 评论(0) 推荐(0) 编辑
摘要: Chapter 8 :动态绑定和id类型1. 示例代码: 1 // 用到的类请参照前面的笔记 2 3 // 两个类中都含有print方法 4 #import "Fraction.h" 5 #import "Complex.h" 6 7 int main(int argc, const char *argv[]) 8 { 9 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];10 11 Fraction *f = [[Fraction alloc] init];12 Complex *c 阅读全文
posted @ 2012-09-28 11:06 BankFish 阅读(127) 评论(0) 推荐(0) 编辑
摘要: Chapter 7 : 继承1. 首先记住:Objective-C不支持多继承。2. 关于Square类继承于Rectangle类的继承示例:Rectangle.h 1 // Rectangle类声明 2 // Rectangle.h文件 3 4 #import <Foundation/Foundation.h> 5 6 // Inherited from NSObject Class 7 @interface Rectangle : NSObject 8 { 9 int width;10 int height;11 }12 13 // 存取器属性14 @property ... 阅读全文
posted @ 2012-09-28 10:46 BankFish 阅读(245) 评论(0) 推荐(0) 编辑
摘要: Chapter 6 : 存取器1. 示例代码: 1 // Car.h文件 2 3 #import <Cocoa/Cocoa.h> 4 5 @interface Car : NSObject 6 { 7 NSString *name; 8 NSMutableArray *tires; 9 Engine *engine;10 }11 12 @property (copy) NSString *name;13 @property (retain) Engine *engine;14 15 - (void)set... 阅读全文
posted @ 2012-09-28 10:07 BankFish 阅读(206) 评论(0) 推荐(0) 编辑