IT English Collection(12) of Archiving

1 前言

    今天我们介绍的归档(Archiving),即是将一组对象转化为对象网络,用来应用或者进程间传输,也就是将对象持久化操作。

2 详述

2.1 正文

    Archiving is the process of converting a group of related objects to a form that can be stored or transferred between applications. The end result of archiving—an archive—is a stream of bytes that records the identity of objects, their encapsulated values, and their relationships with other objects. Unarchiving, the reverse process, takes an archive and reconstitutes an identical network of objects.

    The main value of archiving is that it provides a generic way to make objects persistent. Instead of writing object data out in a special file format, applications frequently store their model objects in archives that they can write out as files. An application can also transfer a network of objects—commonly known as an object graph—to another application using archiving. Applications often do this for pasteboard operations such as copy and paste.
    For its instances to be included in an archive, a class must adopt the NSCoding protocol and implement the required methods for encoding and decoding objects. Cocoa archives can hold Objective-C objects, scalar values, C arrays, structures, and strings. Archives store the types of objects along with the encapsulated data, so an object decoded from a stream of bytes is of the same class as the object that was originally encoded into the stream.
Keyed and Sequential Archivers
    The Foundation framework provides two sets of classes for archiving and unarchiving networks of objects. They include methods for initiating the archiving and unarchiving processes and for encoding and decoding the instance data of your objects. Objects of these classes are sometimes referred to as archivers and unarchivers.
    Keyed archivers and unarchivers (NSKeyedArchiver and NSKeyedUnarchiver). These objects use string keys as identifiers of the data to be encoded and decoded. They are the preferred objects for archiving and unarchiving objects, especially with new applications.
    Sequential archivers and unarchivers (NSArchiver and NSUnarchiver). This “old-style” archiver encodes object state in a certain order; the unarchiver expects to decode object state in the same order. Their intended use is for legacy code; new applications should use keyed archives instead.
Creating and Decoding Keyed Archives
    An application creates an archive by invoking the archiveRootObject:toFile: class method of NSKeyedArchiver. The first parameter of this method takes a reference to the root object of an object graph. Starting with this root object, each object in the graph that conforms to the NSCoding protocol is given an opportunity to encode itself into the archive. The resulting byte stream is written to the specified file.

    Decoding an archive proceeds in the opposite direction. An application calls the NSKeyedUnarchiver class method unarchiveObjectWithFile:. Given an archive file, the method recreates the object graph, asking the class of each object in the graph to decode the relevant data in the byte stream and recreate the object. The method ends by returning a reference to the root object.
    The NSKeyedArchiver class methods archivedDataWithRootObject: and unarchiveObjectWithData: are equivalent to the above methods, except they work with a data object rather than a file.

2.2 生词

encapsulated [ɪn'kæpsəleɪtɪd] adj. 密封的;包在荚膜内的 v. 压缩

reconstitutes [riː'kɒnstɪtjuːt] vt. 重新设立;重新组成

identical [aɪ'dentɪk(ə)l] adj. 同一的;完全相同的

generic [dʒɪ'nerɪk] adj. 类的;一般的

frequently ['friːkw(ə)ntlɪ] adv. 频繁地,经常地

adopt [ə'dɒpt] vt. 采取;接受

scalar ['skeɪlə] adj. 标量的;数量的

along with 连同一起;与一道

originally [ə'rɪdʒɪn(ə)lɪ] adv. 最初,起初

preferred [prɪ'fɜːd] adj. 优先的;首选的

especially [ɪ'speʃ(ə)lɪ; e-] adv. 特别;尤其

Sequential [sɪ'kwenʃ(ə)l] adj. 连续的;相继的

intended [ɪn'tendɪd] adj. 故意的,有意的

legacy code  遗留代码

opportunity [ɒpə'tjuːnɪtɪ] n. 时机,机会

opposite ['ɒpəzɪt; -sɪt] adj. 相反的;对面的

relevant ['relɪv(ə)nt] adj. 有关的;中肯的

equivalent [ɪ'kwɪv(ə)l(ə)nt] adj. 等价的,相等的

3 结语

    以上是所有内容,希望对大家有所帮助。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值