Swift tips, tricks and tools for iOS developers.

read

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).

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.