object-c-System type Object archive

Source: Internet
Author: User

The system type mainly refers to the NSString Nsdictionary,nsarray,nsdata,nsnumber type data (including the corresponding variable type);

These types have implemented the Nscoding protocol, supporting archiving,

Write Method:

Writetofile:atomically:

Read method:

-dictionarywithcontentsoffile:

-arraywithcontentsoffile:

-datawithcontentsoffile:

-stringwithcontentsoffile:

String Object Archive and archive atomically buffer pool
NSString *[email protected] "Hello oc!";


Write
BOOL falg=[str writetofile:@ "Str.txt" Atomically:yes encoding:nsutf8stringencoding Error:nil];
if (FALG) {
NSLog (@ "Str saved successfully!) ");
}

Read
NSString *readstr=[nsstring stringwithcontentsoffile:@ "Str.txt" encoding:nsutf8stringencoding Error:nil];

Array object archiving and solution archiving
Write
Nsarray *[email protected][@ "One", @ "one", @ "three"];
BOOL flag=[arr writetofile:@ "Arr.plist" atomically:yes];
if (flag) {
NSLog (@ "YES");
}

Read out
Nsarray *readarr =[nsarray arraywithcontentsoffile:@ "Arr.plist"];

Dictionary object archiving and solution archiving
Nsdictionary *[email protected]{@ "1": @ "one",
@ "2": @ "a",
@ "3": @ "three"};
Write
BOOL flag = [dic writetofile:@ "Dic.plist" atomically:yes];
if (flag) {
NSLog (@ "YES");
}

Nsdictionary *readdic = [nsdictionary dictionarywithcontentsoffile:@ "Dic.plist"];
NSLog (@ "readdic =%@", readdic);

object-c-System type Object archive

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.