您的位置:首页 > 其它

复杂写法的宏

2015-11-26 21:11 375 查看
// Some simple defines to make life easier on ourself

#if TARGET_OS_IPHONE

#define MakeColor(r, g, b) [UIColor colorWithRed:(r/255.0f) green:(g/255.0f)
blue:(b/255.0f) alpha:1.0f]

#else

#define MakeColor(r, g, b) [NSColor colorWithCalibratedRed:(r/255.0f) green:(g/255.0f)
blue:(b/255.0f) alpha:1.0f]

#endif

#if TARGET_OS_IPHONE

#define OSColor UIColor

#else

#define OSColor NSColor

#endif

// If running in a shell, not all RGB colors will be supported.

// In this case we automatically map to the closest available color.

// In order to provide this mapping, we have a hard-coded set of the standard RGB values available in the shell.

// However, not every shell is the same, and Apple likes to think different even when it comes to shell colors.
//

// 参考写法
#define LOG_LEVEL
2

#define NSLogError(frmt, ...) do{ if(LOG_LEVEL >=
1) NSLog((frmt), ##__VA_ARGS__); } while(0)

#define NSLogWarn(frmt, ...) do{ if(LOG_LEVEL >=
2) NSLog((frmt), ##__VA_ARGS__); } while(0)

#define NSLogInfo(frmt, ...) do{ if(LOG_LEVEL >=
3) NSLog((frmt), ##__VA_ARGS__); } while(0)
#define NSLogVerbose(frmt, ...) do{ if(LOG_LEVEL >=
4) NSLog((frmt), ##__VA_ARGS__); } while(0)

#define LOG_MACRO(isAsynchronous, lvl, flg, ctx, atag, fnct, frmt, ...) \

[DDLog log:isAsynchronous \

level:lvl \

flag:flg \

context:ctx \

file:__FILE__ \

function:fnct \

line:__LINE__ \

tag:atag \
format:(frmt), ##__VA_ARGS__]

//判断区分的宏的写法
#if TARGET_IPHONE_SIMULATOR

#define XATTR_ARCHIVED_NAME @"archived"

#else

#define XATTR_ARCHIVED_NAME @"lumberjack.log.archived"
#endif

#ifndef NSXMLElementDeclarationKind

#define NSXMLElementDeclarationKind DDXMLElementDeclarationKind

#endif

#ifndef NSXMLNotationDeclarationKind

#define NSXMLNotationDeclarationKind DDXMLNotationDeclarationKind
#endif

// The debugging macro adds a significant amount of overhead, and should NOT be enabled on production builds.

#if DEBUG

#define DDXML_DEBUG_MEMORY_ISSUES
0

#else

#define DDXML_DEBUG_MEMORY_ISSUES
0 // Don't change me!
#endif

- (void)inDatabase:(void
(^)(FMDatabase
*db))block {

/* Get the currently executing queue (which should probably be nil, but in theory could be another DB queue

* and then check it against self to make sure we're not about to deadlock. */

FMDatabaseQueue
*currentSyncQueue = (__bridge
id)dispatch_get_specific(kDispatchQueueSpecificKey);

assert(currentSyncQueue !=
self
&&
"inDatabase: was called reentrantly on the same queue, which would lead to a deadlock");

FMDBRetain(self);

dispatch_sync(_queue, ^()
{

FMDatabase
*db = [self
database];

block(db);

if ([db
hasOpenResultSets]) {

NSLog(@"Warning: there is at least one open result set around after performing [FMDatabaseQueue inDatabase:]");

#if defined(DEBUG) && DEBUG

NSSet
*openSetCopy =
FMDBReturnAutoreleased([[db valueForKey:@"_openResultSets"]
copy]);

for
(NSValue
*rsInWrappedInATastyValueMeal
in
openSetCopy) {

FMResultSet
*rs = (FMResultSet
*)[rsInWrappedInATastyValueMeal
pointerValue];

NSLog(@"query: '%@'", [rs
query]);

}

#endif

}

});

FMDBRelease(self);

}

//判断含警告
#if ! __has_feature(objc_arc)

#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: