0

I'm programmatically building an array of dictionaries with hundreds of values I'm pulling from various sources. I then plan to go in and manually change a few of them as needed. I don't want to use this pulling method in the production code, I want to just store it as a vanilla array with dictionaries. However when using NSLog it returns the array obviously, but not as code I can copy and paste. I'd hate to have to go through several hundred values and and manually convert everything to be proper objective c code.

So in short, is there any way to return my array as actual code?

1
  • 1
    why not save the array as plist. it is much easier to read/edit/maintain Commented Apr 22, 2014 at 23:40

1 Answer 1

2

One approach would be to write the final array to a plist file. Then make the plist file part of your project. No need to generate code for the array. Simply load the plist into an array at runtime.

To save the array as a plist:

[myFinalArray writeToFile:somePath atomically:YES];
Sign up to request clarification or add additional context in comments.

2 Comments

I'm still pretty new to the language. This is an awesome solution I didn't even know was an option. Thank you.
Note that in order for this to work, every object in the array's "object graph" (the objects and all the objects they contain, recursively) must be "property list" objects (NSString, NSData, NSDate, NSNumber, NSArray, or NSDictionary objects) If a single object in the array, or in one of the containers that it contains, is not one of those types, the write will fail. If you need to save custom objects or objects of types other than the above list, you can use NSCoding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.