O'Reilly logo

Mac Application Development by Example Beginner's Guide by Robert Wiebe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – writing the readDefaults:forKey: program code

Now we can jump in and write the program code to implement this method as follows:

  1. Start by putting a comment in the NewDefaults.m file that describes the method in plain English:
    /*
        This method will execute the command line tool defaults
        to read a value from a domain for a specific key
     
        Input: 
            a_domain - a reverse domain id for the defaults to read
            a_key - a key value to read
     
        Output:
            Either the string value of the result or Nil if there
            is no value to return.
     */

    Tip

    It's always a good idea to explain our methods using this kind of plain English comment block.

  2. The method needs to match the interface from the .h file. So now we can add the function body to the .m file. Note the opening and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required