Advantages and disadvantages of encoding objects with NSCoding or simply writing data to files

StackOverflow https://stackoverflow.com/questions/4370172

  •  09-10-2019
  •  | 
  •  

Question

I'm curious what the advantages of encoding objects in objective c with NSCoding and writing them to disk may be over simply writing a persistence object to disk. Is there a performance increase in terms of I/O or disk space usage?

Was it helpful?

Solution

Well, most NSCoding implementations will handle object graphs correctly; i.e. if you code a member object that's already been coded to the coder, it won't code it again. Decoding will restore the object graph correctly (so the decoded target object has multiple inbound references). You also get all the built in helper coding functions (for primitive types, and objects).

Other than that, NSCoders are just persistence object generators, so you end up doing similar work, only without the annoyances and common cases handled by Apple. What persistence generator could you write that wouldn't duplicate tonnes of NSCoder functionality?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top