Serialization?
Pointers are great until it comes to needing to write the data that they point to to a file, especially when some of that data that they point to happens to be more pointers and more pointers within that, etc.
NSData performs a shallow write. I need to do a deep write. I can see that I could write a method that will write primitive data and then tell the pointers to write until there are no more pointers, however...
The problem with that is, NSData has no way to open a file and leave it open for appending, that I could tell. I got to looking at CFData functions and my head started to spin. Not sure if that's the right way to go or not.
I could just use an fstream but then I'd have to change most of my files to .mm...
Any advice as to what's the standard way of writing ALL of the data in a class to file? Thanks again!!!
NSData performs a shallow write. I need to do a deep write. I can see that I could write a method that will write primitive data and then tell the pointers to write until there are no more pointers, however...
The problem with that is, NSData has no way to open a file and leave it open for appending, that I could tell. I got to looking at CFData functions and my head started to spin. Not sure if that's the right way to go or not.
I could just use an fstream but then I'd have to change most of my files to .mm...
Any advice as to what's the standard way of writing ALL of the data in a class to file? Thanks again!!!
If by class you mean an Obj-C class, then use actual serialization with initWithCoder:, encodeWithCoder:
http://developer.apple.com/iphone/librar...iving.html
http://developer.apple.com/iphone/librar...iving.html
Yes, I mean Objective-C. Thanks!
bmantzey Wrote:I could just use an fstream but then I'd have to change most of my files to .mm...
fopen, fwrite, fclose are all in C stdlib, and well worth getting comfortable with.
If you want to open a file and repeatedly append to it while staying within Cocoa, use NSFileHandle.
But yes, you should be doing this with NSCoder and friends.
But yes, you should be doing this with NSCoder and friends.
I'm well versed with the fstream classes. I'm trying to learn Cocoa because there's a plethora of convenience classes out there. I'll check out the NSCoder stuff. Thanks again!
bmantzey Wrote:I'm well versed with the fstream classes.
fstream is C++. What I was referring to is C, and usable directly from an Objective-C source file without having to change the way you're compiling it. I just bring them up because I find them to be invaluable tools for any kind of C programming that deals with file I/O.
Hmm, sorry for jumping to what I thought you said. I'll look into it. Thanks again Took!

