iOS Development

Course No. 10-152-139

Assignment 26-2

  • Create a new Xcode command-line project. Name the project Assignment-26-2.
  • Write a program that reads the /usr/share/dict/propernames file on your computer and outputs a JSON version of it.
  • The JSON output will be a dictionary that is keyed by the first letter of the name. As an example here is a small subset of the propernames file.
  • The JSON file that your program will create would look like this for this sample. Your final output will include all the names in the propernames file.
    • Notice that the keys are not sorted. It is not required to sort the keys in your final output file.
  • The output is one dictionary that contains keys of the first letter of the names. The values for each key is an array of names with that first letter.
  • To make sure this is clear let’s look at a very small JSON output file of just one key.

Your Program Features

  • Create a class named ProperNames. This class will contain all the code of the project.
  • The class will need a private NSMutableDictionary property declared in a Class Extension.
  • The class will need two public methods that will be called from the main function of the project.
    • A method that reads the propernames file and loads the names into the dictionary. Read the documentation for NSString for the method needed to extract the first letter of a string.
    • A method that exports the proper names dictionary to a JSON file. The file should have a file extension of .js and be placed in the Desktop directory of your computer.
  • All other methods needed by the program must be declared in the class extension to make them private. There should be more methods than two for the sake of code clarity.
  • Proper error handling must be used when calling methods that have an NSError parameter. This includes:
    • Create a variable that is pointer of type NSError. Do not create an instance of this class.
    • If the method you are calling returns a BOOL then you need to have a variable to hold the return value. Then use an if statement to determine if the method ran successfully.
    • If the method you are calling does not return a BOOL then you should check if an error object was created. This is done by checking the pointer. If the pointer is nil then the method was successful and no error object was created.
  • In the main function in the main.m file you should:
    • Import your class.
    • Instantiate an instance of your class.
    • Send the instance the message to load the propernames file.
    • Send the instance the message to export the file.