iOS Development

Course No. 10-152-139

Assignment 22-1 (Class Extensions)

  • Create a new Xcode command-line project. Name the project Assignment-22-1.
  • Add a class to the project named WordFinder.
  • The class will have no public properties and exactly one public method.
  • All other properties and methods must be declared private.
  • The one public method must be named:
    • - (NSArray *)findWordsWithPrefix:(NSString *)prefix fileName:(NSString *)fileName
  • You must create at least two more private methods.
  • The program will open the input file and output all words that begin with the prefix.
  • The WordFinder class must have an NSMutableArray that will hold all found words.
  • The array of found words is returned by the findWordsWithPrefix:fileName: method.
  • Hint: You might want to checkout the NSString method named hasPrefix:.
  • In the main function of the main.m file:
    • Import the WordFinder class.
    • Instantiate one instance of the WordFinder class.
    • Send the findWordsWithPrefix:fileName: message to the instance using “/usr/share/dict/words” as the file name and whatever you want for the prefix. Using a larger prefix like “brak” will result in fewer found words.