[Objective-C] NSURL, NSMutableArray, and NSMutableDictionary

Objective-C is such a versatile language. One of the main hardships when coding with Objective-C is that the language provides many different methods for solving the same problems. This is due to its robust API, with a plethora of library methods that can be utilized.

NSMutableArray gives you the ability to add or remove items from locations within a collection. There are many built-in methods that can be used to change and arrange items within the mutable array. Arrays are a great way to reliably record the order of their elements, and as such, make a great tool for sorting and manipulating lists of data.

NSURL is very useful in creating objects that contain the location of a particular resource on a remote server. I will explain its use in the coding challenge below. For now, one of the benefits of NSURL is the ability manipulate the contents of a particular file on a remote server.

NSMutableDictionary gives the dictionary interface to a particular object, allowing that object to hold mutable keys and values. Keys and values are paired within a dictionary, and each Key must be unique within a particular dictionary.

One of the more difficult beginner tasks I encountered in Objective-C was to build a program that could read a text file from a remote location on the computer, and store the contents of the text file within a mutable dictionary.

Before we begin to type code, we must approach this task by asking the right questions: What do I actually need to do? If I am not sure, how should I break it down in to smaller pieces? What should be displayed at the end? What objects are required in order for this program to work? I found that the task at hand had these requirements:

  1. An NSURL object to read and pull the contents of the text file.
  2. An NSArray componentsSeparatedByString method to copy the contents of the text file to an NSArray object.
  3. A Class that will initialize an object for storing the contents of the NSArray object.
  4. An NSMutableArray for storing the initialized object.

After we’ve asked the questions, then we can begin to attempt the coding process.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s