Hey all, first post, but I've been lurking for a few weeks. I'm a C++ coder, and I've been tasked with learning the Mac world. So far so good. I've read Cocoa programming for Mac OSX and written a few sample apps, and I think I'm ready to dig in. EXCEPT, I'd like some advice before I dive in.
My first program will be similar to an address book. I need to store an object with simple data such as, strings, gregorian dates, etc... and do file io on it. My first instinct was to create my own class, and create an NSMutable array, and when it came time to do file io, convert my entire array into one gigantic string with magic character separators, and deconstruct/reconstruct my object, and save out and load the entire string at once into a single file. That worked, but I was worried about the magic character seperator (heaven forbid someone use a magic character in one of their strings).
I'm now second guessing that approach entirely. I've run into a few classes that seem to be very useful for what I'm doing. NSDictionary seems ideal, however, it seems like if I wanted to use that, each object would need it's own file... so I could potentially have 300 saved out NSDictionaries each with the same keys... it seems wrong for obvious reasons. I next thought about doing something similar to above, but use an array of NSDictionaries and then do the same construction deconstruction into and out of a string as I was doing before, but there must be a better way.
I'm researching now into NSCoder and NSCoding, and it seems promising. This approach would be using my own custom class, and just handling my own fileio.
So my question to you is... how would YOU handle the data in a program like this? Is there some native data type I'm unaware of that will contain a number of objects(or dictionaries) and do file io brilliantly? Or is doing it myself with NSCoder the best approach? Any help would be very much appreciated.
-Than
My first program will be similar to an address book. I need to store an object with simple data such as, strings, gregorian dates, etc... and do file io on it. My first instinct was to create my own class, and create an NSMutable array, and when it came time to do file io, convert my entire array into one gigantic string with magic character separators, and deconstruct/reconstruct my object, and save out and load the entire string at once into a single file. That worked, but I was worried about the magic character seperator (heaven forbid someone use a magic character in one of their strings).
I'm now second guessing that approach entirely. I've run into a few classes that seem to be very useful for what I'm doing. NSDictionary seems ideal, however, it seems like if I wanted to use that, each object would need it's own file... so I could potentially have 300 saved out NSDictionaries each with the same keys... it seems wrong for obvious reasons. I next thought about doing something similar to above, but use an array of NSDictionaries and then do the same construction deconstruction into and out of a string as I was doing before, but there must be a better way.
I'm researching now into NSCoder and NSCoding, and it seems promising. This approach would be using my own custom class, and just handling my own fileio.
So my question to you is... how would YOU handle the data in a program like this? Is there some native data type I'm unaware of that will contain a number of objects(or dictionaries) and do file io brilliantly? Or is doing it myself with NSCoder the best approach? Any help would be very much appreciated.
-Than