I’ve seen some of the example of using NSCoder to archive the things in your application
@interface MyApplicationData : NSObject <NSCoding, NSCopying> {
NSMutableArray* items;
NSMutableArray* categories;
}
Please see this thread. How to use NSCoder
Why does this improve the performance of your app? isn’t that doing more things in your application? Can anyone tell me why and when you want to use archive?
EDITED:
Quoted from a book, iOS 5 programming pushing the limit- Under Method for Storing your Cache: “Caching or saving data can be done either by storing it as archives of your data models (using NSKeyedArchiver) or using a higher-level database like raw SQLite or using object serialization framework like Core Data…” “….NSKeyedArchiver is implemented by implementing the NSCoding protocol.”
I thought NSCoding or NSCoder can be used for Caching and it will improve performance. So is it not good practice to use it for caching?
Thanks in advance.
well, you need some context — serialization may or may not “improve performance”. it could improve performance over alternative serialized representations. that may make a difference, or it may not be significant.
well, if you have a complex structure represented in xml/plist as opposed to a serialized object, then no — the object that knows how to encode/decode itself could be much more performant than xml or json or some other intermediate representation (for a number of reasons). it can also be easier to manage, and represent complex structures more easily (in comparison to intermediate serialization representations).
typically when you want to save an object or object graph’s state to disk, or for transfer to another machine.
imagine you have document data, and you want to restore that document when the document is reopened — your program must create a representation which correctly reconstructs the object or object graph’s state later on.