![]() |
|
Serialization? - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html) +--- Thread: Serialization? (/thread-746.html) |
Serialization? - bmantzey - Sep 16, 2009 02:49 PM 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!!!
Serialization? - SethWillits - Sep 16, 2009 02:52 PM If by class you mean an Obj-C class, then use actual serialization with initWithCoder:, encodeWithCoder: http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/Archiving/Archiving.html Serialization? - bmantzey - Sep 16, 2009 03:05 PM Yes, I mean Objective-C. Thanks! Serialization? - ThemsAllTook - Sep 16, 2009 04:16 PM 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. Serialization? - Mark Levin - Sep 21, 2009 12:19 PM 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. Serialization? - bmantzey - Sep 23, 2009 11:43 AM 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! Serialization? - ThemsAllTook - Sep 23, 2009 01:15 PM 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. Serialization? - bmantzey - Sep 23, 2009 09:10 PM Hmm, sorry for jumping to what I thought you said. I'll look into it. Thanks again Took! |