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

NSDictionary Literals In Objective-C

I’ve previously written about NSNumber and NSArray literals, let’s have a look at NSDictionary literals.

Before we get started, a quick note, to use literals you will need to be running Xcode 4.4 or greater as well as the Apple LLVM compiler 4.0 or greater.

As with NSString objects, which allow definition using literal syntax:

NSString *str = @"Some string";

you can now create NSDictionary objects using literals. A range of examples follow, showing the old style definition as well as the new literal syntax:
Continue reading