objective c - Save NSMutableArray to disk -
I have an NSMutableArray, which keeps things of the type of person (NSString, NSString, int) Method Save this array to disk and load it later.
I have read a lot about the serialization but I have never done that, this may not be the easiest way for me.
The first step to implementing your individual class is to implement two methods of NSCoding Protocol Basic Strategy To serialize and to simulate the example variable of each object that you want to be in between the sessions.
#pragma mark NSCoding Protocol - (zero) encodeWithCoder :( Encoder *) Encoder; {[Encoder encoded object: [for self-fu]: @ "afu"]; [Encoder encode repeating: [for self defense]: @ "bar"]; } - (id) initWithCoder: (encoder *) decoder; {If (! [Super init]) return zero; [Self setfu: [decoder decoded objectForcae: @ "foo"]]; [Self setbar: [decoder decodedbauforki: @ "bar"]]; Self return; } To actually write objects to disk, you can use the NSArray's writeToFile: method or use the NSKeyedUnarchiver class if you Want to know how it's done. In both cases, you can put your data into another data structure (for example in a dictionary) if you want to include other items (such as file format number) in your data file.
Comments
Post a Comment