Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ iOS persistence of data archiving NSKeyedArchiver     - Linux C source code (sockettype: socket descriptor determination function) (Programming)

- System-level alias vs Oracle ADR functionality (Database)

- ARP Linux-related operations (Linux)

- Lazarus IDE Start Basics Tutorial (Linux)

- Installation Flow N Play- interface stylized video player on Ubuntu (Linux)

- Graphing tool: Gnuplot (Linux)

- Generators and iterators in Python (Programming)

- Github with .gitignore ignore specified file (Linux)

- Linux6.1 / 6.5 dual-NIC Binding (Linux)

- MySQL + Heartbeat + DRBD deployment architecture (Server)

- Ubuntu system grub repair method (Linux)

- Linux System Getting Started Tutorial: permission to permanently modify the USB device in Linux (Linux)

- Windows Remote Desktop Management CentOS 6.4 (Linux)

- SME Linux network security policy server security (Linux)

- Actual custom yum repository ---- gem commands commonly used parameters (Linux)

- Linux environment RabbitMQ installation and monitoring of plug-in installation (Linux)

- Examples of RAID levels and achieve Operational Details (Linux)

- Linux open handle limit adjustment (Linux)

- Modifying the system registry protection server security (Linux)

- RPM package management under Linux (Linux)

  iOS persistence of data archiving NSKeyedArchiver
  Add Date : 2017-04-19      
  IOS data persistence is divided into three types:

Property list (Property List custom, NSUSErDefaults)
Archive (NSKeyedArchiver)
Database (SQLite, Core Data, third-party libraries, etc.)
Here to introduce a major archive NSKeyedArchiver.

 Archive (aka serialization), the object is converted to byte code in the form of a file stored on disk; or when the program is running again rewrite the open program, you can restore them by solving archiving (deserialization) object.


Foundation Framework for archiving objects
The contents of the custom archive
Custom object archive

< A> Foundation framework for archiving objects

// Get the file path
    NSString * documentPath = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString * filePath = [documentPath stringByAppendingPathComponent: @ "file.archiver"];
// Archive (serialization)
NSArray * archiveAry = @ [@ "jereh", @ "ios"];
if ([NSKeyedArchiver archiveRootObject: archiveAry toFile: filePath]) {
        NSLog (@ "Archiver success");
// Solutions for Archiving (deserialization)
NSArray * unArchiveAry = [NSKeyedUnarchiver unarchiveObjectWithFile: filePath];
NSLog (@ "% @", unArchiveAry);

Archiving Archiving Reconciliation simple steps
You can only archive an object if it is an archive multiple objects need to be separated
Objects are archived in the Foundation framework objects
Archive unarchive any object which need to be archived unarchive the entire file
After the filing is encrypted, so the extension of the archive can be freely taken

< B> for custom content archive

// Get the file path
NSString * documentPath = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString * filePath = [documentPath stringByAppendingPathComponent: @ "file.archiver"];
// 1. Use NSData to store archived data
NSMutableData * archiverData = [NSMutableData data];
// 2. Create archive objects
NSKeyedArchiver * archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData: archiverData];
// 3. Add the contents of the archive (set key-value pairs)
 [Archiver encodeObject: @ "jereh" forKey: @ "name"];
 [Archiver encodeInt: 20 forKey: @ "age"];
 [Archiver encodeObject: @ [@ "ios", @ "oc"] forKey: @ "language"];
// 4. Complete archive
 [Archiver finishEncoding];
// 5. The information is stored on disk archive
if ([archiverData writeToFile: filePath atomically: YES]) {
     NSLog (@ "archiver success");
// Archive Solutions
// 1 read from the disk file to generate NSData instance
NSData * unarchiverData = [NSData dataWithContentsOfFile: filePath];
// 2. Create and initialize an instance according to Data Solutions archive objects
NSKeyedUnarchiver * unachiver = [[NSKeyedUnarchiver alloc] initForReadingWithData: unarchiverData];
// 3. Archiving solutions, based on key values ​​access
NSString * name = [unachiver decodeObjectForKey: @ "name"];
int age = [unachiver decodeIntForKey: @ "age"];
NSArray * ary = [unachiver decodeObjectForKey: @ "language"];
NSLog (@ "name =% @ age =% i ary =% @", name, age, ary);

Keyed in the archive, the archive each field has a key value, key value to match the key value archiving solution archives
Keyed Archiving can store multiple objects once
Objects are archived in the Foundation framework objects
Archive unarchive any object which need to be archived unarchive the entire file
After the filing is encrypted, so the extension of the archive can be freely taken

< C> to target custom archive

#define IDNUM @ "idNum"
#define NAME @ "name"

@interface Student: NSObject < NSCoding>
@property (nonatomic, assign) int idNum;
@property (nonatomic, copy) NSString * name;

@implementation Student

#pragma mark coding process of coding object properties
- (Void) encodeWithCoder: (NSCoder *) aCoder
    [ACoder encodeInt: _idNum forKey: IDNUM];
    [ACoder encodeObject: _name forKey: NAME];

#pragma mark decoding decodes archive data to initialize the object
- (Id) initWithCoder: (NSCoder *) aDecoder
    if (self = [super init]) {
        _idNum = [aDecoder decodeIntForKey: IDNUM];
        _name = [aDecoder decodeObjectForKey: NAME];
    return self;

Custom objects and custom content archive archive reconciliation steps and use the same
Since the object definition archiving NSCoding need to implement the agreement, and implement the protocol Method
NSCoding protocol has two methods:
encodeWithCoder method to encode object properties, called when the object archive
initWithCoder archive data decoding method to initialize the object is called when the object archiving solution

to sum up:

Archiving can be used to archive reconciliation persistent store small amounts of data and reading
Property lists are only stored Foundation framework objects, in addition to the archive can be archived in the Foundation framework objects can also be archived to achieve a custom object NSCoding agreement
Create archive files are encrypted
- Swift notes - let you two hours to learn Swift (Programming)
- CentOS 7 Configure logging (VirtualBox) (Linux)
- Several configuration changes illustrate deployment of PHP (Server)
- Android Scroller call mechanism and the relationship of computeScroll (Programming)
- CentOS installed JDK8 (Linux)
- VPN built on CentOS (Server)
- Transfer files and permissions from Windows to Linux system by Samba (Linux)
- DRBD Principle and Features Overview (Server)
- Oracle archive log size than the size of the online journal of the much smaller (Database)
- Implement Oracle dynamic registration of non-standard port 1521 (Database)
- Django Web dynamic three linkage (Programming)
- Batch download files using the explorer under Windows Server 2008 R2 (Server)
- LVM Disk Manager Application (Linux)
- Eclipse-4.4 crash problem solving under Debian-7.6 (Linux)
- Java object serialization and deserialization (Programming)
- CentOS / Linux NIC set IP address configuration (Linux)
- Python Socket Network Programming (Programming)
- The script Linux command (Linux)
- AngularJS asynchronous service testing and Mocking (Programming)
- Linux administrator should command: sed and awk (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.