ios - Differences with archiveRootObject:toFile: and writeToFile: -


recently, i'm learning nskeyedarchiver , nskeyedunarchiver. found there 3 ways archive array , i'm trying figure out differences.

1.using archiverootobject:tofile:

    [nskeyedarchiver archiverootobject:testarray tofile:filepath]; 

2.get data archiveddatawithrootobject: , write file

    nsdata *data = [nskeyedarchiver archiveddatawithrootobject:testarray];     [data writetofile:filepath atomically:yes]; 

3.using encodeobject: data

    nsmutabledata *data = [nsmutabledata data];     nskeyedarchiver *archiver = [[nskeyedarchiver alloc] initforwritingwithmutabledata:data];     [archiver encodeobject:testarray forkey:@"testarray"];     [archiver finishencoding];     [data writetofile:path atomically:yes]; 

after testing, found ways above work fine , write same content file.

q1: what's differences ways above?

q2: can use nsdata in 3rd way?

the first 1 doesn't give choice of data. go file. use second way to, example, send data across network connection. more flexible. 3rd way same thing except can put single objects it. i'm not sure work array stands, might. more flexible don't need have array or dictionary ready it.

that's pretty it. convenience vs flexibility.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -