avp::ptr weblog

Everything that is in our mind.

Archive for the ‘objective-c’ tag

Custom NSLog for Xcode 4

without comments

This post describes how you can to setup a custom NSLog snippet in Xcode 4. By default, this custom NSLog prints the class and method name of the position it is inserted.

NSLog auto completion

NSLog auto completion

Please follow these steps to add the code snippet to the scripts in Xcode 4.

  1. Copy and paste the following code into your editor. Anywhere.
    NSLog(@"%@ %@", self.className, NSStringFromSelector(_cmd)); /* DEBUG LOG */
  2. Open up the code snippets library which sits in the utility pane on the right side. Look for the curly braces {}.
  3. Highlight the above mentioned code – click and hold the mouse over the text  (for a short while) – drag them into the code snippet library.
  4. Afterwards you can edit the snippet and add a title, summary and a completion shortcut. I used the following settings:
                  Title: Custom NSLog (Class & method name)
                Summary: NSLog prints the class and method name
               Platform: All
               Language: Objective-C
    Completion Shortcut: NSLog
      Completion Scopes: All
Custom NSLog snippet

Custom NSLog snippet

You are welcome to comment and post your custom code snippets!
This article is inspired by the post “Easy Doxygen code snippets for Xcode 4” by Chris Powell.

Written by tobi

October 26th, 2011 at 9:06 pm