What is the best way to store data in an objective-c model?
I am writing an objective-c model to hold all of the data parsed from an XML connection. I am using an NSURLConnection to download the data asynchronously and it is then passed to the parser. I have done this before, but not with such a large xml file. I would like to garner some opinions on the best way to store the data. Here are some options:
- Create a bunch of NSMutableDictionary's that represent the sections in the xml. Then add a key/value to these dictionaries with the child tags.
Create structs to hold the data as such:
`struct section_one { NSString *string1; NSString *string2; } sectionOne;
The only thing I'm worried about is how to go about m开发者_开发知识库anaging the memory of the strings inside the struct. Should I copy the strings when I am instantiating them and release each individual string in the dealloc of the Model class.
Overall, I would just like some suggestions as to how to store the data.
I'd suggest using NSDictionary instances nested inside another NSDictionary (whether these need to mutable or not depends on how you intend to use them, so I won't comment on that). The keys to the top-level dictionary could then be sectionOne, sectionTwo, etc., and their corresponding values would be the nested dictionary instances.
精彩评论