Reputation: 444
As the title reads, how could I define a custom NSAssert
which would include the line, class, and formatting as per my NSLog
below:
#define NSLog(__FORMAT__, ...) NSLog((@"%@: " __FORMAT__), NSStringFromClass([self class]), ##__VA_ARGS__)
The problem is that NSAssert
has a BOOL value first before the rest of the arguments are taken under account. I can't seem to find a solution without taking out the arguments and separating them.
Is there a better way to solve this?
Long story short, I'm looking for something like this:
#define DebugAssert(__VA_ARGS__[0], @"%@: %@", NSStringFromClass([self class]), __VA_ARGS__[1])
Upvotes: 0
Views: 90
Reputation: 90521
The NSAssert
macro is defined like this:
#define NSAssert(condition, desc, ...) /* the implementation */
So, the condition is already a separate parameter from the format string and the variable argument list. There should be no problem doing something similar to what you did for NSLog
:
#define MyAssert(condition, desc, ...) \
NSAssert(condition, (@"%@: " desc), NSStringFromClass([self class]), ##__VA_ARGS__)
Upvotes: 1