Using Rob's comments and some ideas from โios5 Programming: Pushing the Limitsโ and the Lumberjack framework, here is a macro to make the debugger stop and allow continuation during the approval in DEBUG build, but otherwise do as it always happens during RELEASE (or nothing at all -DEBUG ).
#ifdef DEBUG #define MyAssert(condition, desc, ...) \ if (!(condition)) { \ NSLog((desc), ## __VA_ARGS__); \ if (AmIBeingDebugged()) \ kill (getpid(), SIGSTOP); \ else { \ NSLog(@"%@, %d: could not break into debugger.", THIS_FILE, __LINE__); \ } \ } #define MyCAssert(condition, desc, ...) \ if (!(condition)) { \ NSLog((desc), ## __VA_ARGS__); \ if (AmIBeingDebugged()) \ kill (getpid(), SIGSTOP); \ else \ NSLog(@"%@, %d: could not break into debugger.", THIS_FILE, __LINE__)); \ } \ } #else //NOT in DEBUG #define MyAssert(condition, desc, ...) \ if (!(condition)) { \ DDLogError((desc), ## __VA_ARGS__); \ //use NSLog if not using Lumberjack NSAssert((condition), (desc), ## __VA_ARGS__); \ } #define MyCAssert(condition, desc, ...) \ if (!(condition)) { \ DDLogError((desc), ## __VA_ARGS__); \ //use NSLog if not using Lumberjack NSCAssert((condition), (desc), ## __VA_ARGS__); \ } #endif //end DEBUG #endif
These macros require the AmIBeingDebugged() function, which you can get from Apple here. Rob gave: Technical Q&A QA1631: Detecting a Debugger. (You also need to define DEBUG in the build settings.)
Note that I chose Lumberjack DDLogError() over NSLog() on non- DEBUG lines, because it will spit out the method, file number, and line number where the fatal statement occurred.
Merk
source share