I'm currently traducing the posts in english, my english is not very good, so if you find errors feel free to contact me.
  • Improving NSLog()

    When you debug an app, you often need to print informations on screen to check out if everything is ok etc… But when you are done and you are ready to release your application it’s a real pain in the ass to comment or remove all the call to these functions, plus they might be useful later.
    To fix this problem you just need to define a macro that indicates if you are in a debug phase or not, if it’s the case informations will be printed on the screen otherwise nothing will happen.
    Not so long age I found a article who just talk about this, and in the end a code was proposed :

    1
    2
    3
    4
    5
    6
    
    #ifdef DEBUG
    #define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
    #else
    #define DLog(...)
    #endif
    #define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

    Place this code in the [PROJECT_NAME]_Prefix.pch file, and it’s almost done ;)

    The macro DLog() works exaclty like NSLog(), so you can pass arguments etc… the advantage is that the line and the function name will be printed thanks to __PRETTY_FUNCTION__ & __LINE__ macros.
    As for the macro ALog(), it remplaces NSLog() and will always produce an output.

    The last thing you have to do is to define the DEBUG macro. In XCode go to project information, chose Debug configuration and in the Preprocessing part look for the line Preprocessor Macros and add it :

    1
    
    DEBUG=1

    See ya!


  • Débugger une Préférence Pane avec XCode

    Si ça peut aider certaines personnes qui comptent développer une Préférence Pane, voici comment la debugger dans XCode, parce que le debug à coup de NSlog() et de Console c’est carrément anti-productif.

    Ouvrez votre projet XCode, dans le menu Project choisissez New Custom Executable


    Dans le champ Executable Path choisissez l’application Préférences Système, et mettez ce que vous voulez pour le nom de l’exécutable.

    Voilà, vous pouvez maintenant placer des breakpoints dans votre code et debuger votre projet.
    Lorsque vous cliquerez sur Debug pour lancer le projet, l’application Préférences Système va se lancer, il ne vous restera plus qu’à cliquer sur votre préférence Pane pour la charger et faire le nécessaire pour atteindre votre breakpoint.

    See ya !