1. assert
NSAssert( scene != nil, @"Argument must be non-nil");2 NSLog
#ifdef DEBUG
#include
#define DLogm() NSLog([NSString stringWithFormat:@"[%s:%d %@]",basename(__FILE__),__LINE__,NSStringFromSelector(_cmd)])
#define DLog(format, ...) NSLog([NSString stringWithFormat:@"[%s:%d %@] %@",basename(__FILE__),__LINE__,NSStringFromSelector(_cmd),format], ##__VA_ARGS__)
#define DLogv(var) NSLog([NSString stringWithFormat:@"[%s:%d %@] "# var "=%@",basename(__FILE__),__LINE__,NSStringFromSelector(_cmd), var] )
#else
#define DLog(...) /* */
#define DLogv(var) /* */
#define DLogm() /* */
#endif
#ifdef DEBUG#define NSLog( s, ... ) NSLog( @"<%p> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] ) #else
#define NSLog( s, ... )
#endif
3. 单例模式
// Init
+ (SimpleAudioEngine *) sharedEngine
{
@synchronized(self) {
if (!sharedEngine)
sharedEngine = [[SimpleAudioEngine alloc] init];
}
return sharedEngine;
}