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

Storing CGPoint, CGSize and CGRect in Collections using NSValue

In an earlier post CGRect, CGSize and CGPoint Functions I demonstrated a number of geometry structures available for representing a point (CGPoint – x and y coordinates), size (CGSize – height and width) and rectangles (CGRect – combination of both).

Unfortunately, you cannot directly store any of the above in a collection, for example an array, as each of these is a C structure, not an object. In this post I will show you how to store CGPoint CGRect CGSize in an Objective-C collection.

Continue reading