开发者

What is the best way to store data in an objective-c model?

开发者 https://www.devze.com 2022-12-22 08:00 出处:网络
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 don

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:

  1. 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.
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号