What's the best way to store and retrieve multi-dimensional NSMutableArrays?

前端 未结 3 809
挽巷
挽巷 2021-02-10 04:45

I\'m storing a bunch of data in a .plist file (in the application documents folder), and it\'s structured like this:

Dictionary {
    \"description\" = \"String          


        
3条回答
  •  醉话见心
    2021-02-10 05:13

    Instead of writing all that custom class junk, you should use NSPropertyListSerialization. Specifically, see the propertyListWithData:options:format:error: method. Example usage:

    NSMutableDictionary *d = [NSPropertyListSerialization propertyListWithData:[NSData dataWithContentsOfFile:@"path/to/file"] 
                                                                       options:NSPropertyListMutableContainers
                                                                        format:NULL
                                                                         error:NULL];
    

    This will make all the containers mutable, but keep the leaf nodes (e.g. NSStrings) immutable. There's also an option to make the leaves mutable too.

提交回复
热议问题