Read and Write NSArray, NSDictionary and NSSet to a File

With just a few lines of code, you can read/write collections to/from files. The code below shows examples for writing and reading both NSArray and NSDictionary objects, the same logic would apply to an NSSet (or other collection type).

The example below starts by populating both an array and dictionary, each using the Objective-C literal syntax. Read more about using NSArray literals and NSDictionary literals.

Continue reading

Read Files from the IOS Application Bundle

Below are a few lines of code to get you started if you need to open and read a file that is stored in the application bundle. Files could be anything from help text that your application displays to specific content that facilitates testing.

As an example of the later, often times I find it helpful to put json (or xml) content into a file that I know is valid based on a remote server that I will eventually connect with. I add this file to the application bundle and read it into an internal data structure. I can then do various tests with known data, and once that is working, I can then proceed to the networking side of things to connect and retrieve live data.

Continue reading