Archiving

  面向对象的程序在运行时会创建一个复杂的对象图。开发者经常要以二进制流的方法序列化这个图,该过程称为archiving,也叫存档。这个二进制流可通过网络连接发送,也可以写进文件。当需要从二进制流类型重新创建对象图时,可使用unarchive.重新开始时,它将对象从编译器创建的NIB文件中unarchive就可以。

  尽管对象有成员变量,也定义了方法,但只有成员变量和类的名字可进行存档,也就是说只有数据可存档,而代码不行。假如一个程序存档一个对象,另一个程序unarchive同一个对象时,这两个程序必须有这个类的代码。

1.NSCoder和NSCoding

  有个命令为NSCoding的protocol,假如开发者实现了NSCoding(在.h文件中指明实现了NSCoding协议),将实现下面的方法:

  -(id)initWithCoder:(NSCoder *)coder

  -(void)encodeWithCoder:(NSCoder*)coder

  NSCoder是二进制流的抽象,开发者可以把数据写入coder,也可以从coder中读取数据。对象中的initWithCoder:方法将从coder中读取数据,并将数据保存到它的成员变量。对象中的encodeWithCoder:方法读取他的实例变量的值,然后将那些值写入code。NSCoder是一个抽象类,不能被实例化。

  1.1编码

    编码常用的的一些方法:

-(void)encodeObject:(id)anObject  forKey:(NSString*)key;

-(void)encodeBool:(BOOL) boolv forKey:(NSString*)key;

-(void)encodeDouble:(double)realv  forKey:(NSString*)key;

-(void)encodeFloat:(float)realv  forKey:(NSString*)key;

-(void)encodeInt:(int)intv  forKey:(NSString*)key;

例如:

-(void)encodeWithCoder:(NSCoder *)coder

{

//    [super encodeWithCoder:coder];

[coder encodeObject:personName forKey:@"personName"];

[coder encodeFloat:expectedRaise forKey:@"expectedRaise"];

}

  1.2 解码

  将数据从coder中解码时,可以用以下方法:

- (double)decodeObjectForKey:(NSString *)key

- (double)decodeBoolForKey:(NSString *)key

- (double)decodeDoubleForKey:(NSString *)key

- (double)decodeFloatForKey:(NSString *)key

- (double)decodeIntForKey:(NSString *)key

例如:

-(id)initWithCoder:(NSCoder *)coder

{

self = [super init];

if (self) {

personName = [coder decodeObjectForKey:@"personName"];

expectedRaise = [coder decodeFloatForKey:@"expectedRaise"];

}

return self;

}

时间: 2024-11-05 15:17:51

Archiving的相关文章

Linux - Archiving and Compression

File archiving is used when one or more files need to be transmitted or stored as efficiently as possible. There are two aspects to this: Archiving – Combining multiple files into one, which eliminates the overhead in individual files and makes it ea

Oracle 12c 新特性之 数据库内归档(In-Database Archiving)

Oracle Database 12c中引入了 In-Database Archiving的新特性, 该特性允许用户通过对表上的数据行标记为inactive不活跃的,以归档数据. 这些inactive的数据行可以通过压缩进一部优化,且对应用来说默认不可见.该特性可以对现有代码做最少改动的情况下,实现了这种"标记删除"的功能和需求. 12c之前:有些应用有"标记删除"的概念,即不是删除数据,而是数据依然保留在表中,只是对应用不可见而已.这种需求通常通过如下方法实现:1

Oracle 12C -- in-database archiving

在同一张表中,通过将row置为inactive状态来实现数据的归档.数据库中,可以对那些inactive row进行压缩优化.在实现归档的同时,应用可以被限制只访问那些active状态的数据.默认情况下,那些inactive row对应用是不可见得. 开启表的in-database archiving功能,在创建表的时候要使用关键字"row archival".使用关键字"row archival"创建的表会增加一个隐藏列:ora_archive_state. SQ

Lab - Archiving and Unarchiving Files

By performing this lab, students will learn how to work with archive files. In this lab, you will perform the following tasks: Create archive files using tar with and without compression Compress and uncompress files into a gzip archive file Compress

File Compression and Archiving in linux (linux 中文件的归档)

1. Compressing Files at the Shell Prompt Red Hat Enterprise Linux provides the bzip2, gzip, and zip tools for compression from a shell prompt. The bzip2 compression tool is recommended because it provides the most compression and is found on most UNI

[Hive - LanguageManual] Archiving for File Count Reduction

Archiving for File Count Reduction Note: Archiving should be considered an advanced command due to the caveats involved. Archiving for File Count Reduction Overview Settings Usage Archive Unarchive Cautions and Limitations Under the Hood Overview Due

Object archiving

https://developer.apple.com/library/content/documentation/General/Conceptual/DevPedia-CocoaCore/Archiving.html#//apple_ref/doc/uid/TP40008195-CH1-SW1 Object archiving Archiving is the process of converting a group of related objects to a form that ca

EBS Archiving and Purging: You Know you need to

A number of trends in the IT industry have contributed to the increasing size of ERP application databases and show no signs of abating.  These include dramatic reductions over recent years in the cost of disk, such that it has often been easier to b

log file switch (archiving needed) 等待事件一例

一.环境描述Oracle 11g RAC 二.问题描述客户执行批处理长时间无法完成. 三.问题处理过程 1.查看等待事件 SQL> select inst_id,event,count(*) from gv$session where wait_class<>'Idle' group by inst_id,event order by 1,2; INST_ID EVENT COUNT(*) ---------- ----------------------------------- --