Database Reference
In-Depth Information
Prefix.pch
. It's what I am used to, and I always know where to look for it. You
will find a similar consistency in some other files such as
Info.plist
and
AppDele-
gate.[m|h]
. Whenever you see a reference to one of these files in this topic and
you cannot find it in your project, try prepending
${ProjectName}_
to the front,
and I suspect you will locate it.
#ifdef DEBUG
#define DLog(...) NSLog(@
"%s(%p) %@"
, __PRETTY_FUNCTION__, self,
\
[NSString stringWithFormat:__VA_ARGS__])
#define ALog(...) { \
NSLog(@
"%s(%p) %@"
, __PRETTY_FUNCTION__, self, \
[NSString stringWithFormat:__VA_ARGS__]); \
[[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString \
stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] \
file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding]\
lineNumber:__LINE__ description:__VA_ARGS__];
}
#else
#define DLog(...)
do
{ }
while
(0)
#ifndef NS_BLOCK_ASSERTIONS
#define NS_BLOCK_ASSERTIONS
#endif
#define ALog(...) NSLog(@
"%s(%p) %@"
, __PRETTY_FUNCTION__, self,
\
[NSString stringWithFormat:__VA_ARGS__])
#endif
#define ZAssert(condition, ...)
do
{
\
if
(!(condition)) {
\
ALog(__VA_ARGS__);
\
}
\
}
while
(0)
\
A2.2 What Do They Do?
At the core of this collection of macro code are three functions:
DLog
,
ALog
, and
ZAssert
.
DLog
is designed to be a debug version of
NSLog
. It has the same syntax as
NSLog
, with one very important difference. If there is no
DEBUG
compiler flag
set,
DLog
will compile down into a no-op. This allows us to add as many
DLog
statements to our code as we think is appropriate without worrying about
them degrading the performance of the production application.
The second of these macros is the
ALog
.
ALog
is very similar to
NSLog
; in fact, it
has the same syntax—but it performs a very different function.
ALog
, when
the
DEBUG
compiler flag is set, will throw an
NSAssertion
whenever it is hit. In
addition, when the
DEBUG
compiler flag
is not set
, it will still print its results
out to the console, just like a default
NSLog
would. This functionality is ideal