More Informative NSLog’s with Prefix Headers

    August 29th, 2011 Posted by: - posted under:Snippets » Uncategorized

    Hello iCoders,

    I have a quick tip today that I have been using in some of my development that you guys may find helpful in yours. Lately I’ve been developing a Framework. We mentioned a little something about it earlier here on iCodeBlog. When developing a .framework, a lot of times during my work I couldn’t place break points in the code and had to rely mostly on NSLog. NSLog however really wasn’t doing the job for me. So I made 2 of my own NSLog’s that I have been using to work.

    How it Works

    With your Xcode projects there is a piece of code called the prefix header that is essentially included in every class in your project. This is set up in your Build Settings under the “Prefix Header”. You can put code in here that will be available to every class. Below I have the Prefix Header that I use in my projects. I define 3 things in this Prefix Header.

    • A debug constant declaration
    • A DLog() method declaration
    • A DStep() method declaration


    • The debug constant must be set to 1 for the debug logs to print out. This is nice for turing off all logging before sending off to the App Store. DStep prints out whatever you pass in with a big line of ‘******************’ above and below it. I use it to mark big steps in execution to quickly look through logs. DLog works just like NSLog() except it prints the method and line along with it and once again puts ‘**************’ above and below. Customize them if you like and try them in your development process today! Happy Coding.

      Follow me on Twitter @cruffenach

      EDIT: The code posted here before was malformed by out code formatting plugin. My apologies. The GIST below has the correct code.