复杂写法的宏
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
#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
相关文章推荐
- Hybrid选型和PhoneGap开发环境搭建
- iOS版PhoneGap原理分析
- android-Fragment
- 兔子-提高xampp中php的版本/提高php项目的版本
- 文章标题
- 安装PHP运行环境时候vcruntime140.dll问题的解决方法
- Eclipse 启动问题:'Initilizing Java Tooling' has encountered a problem(。。。)
- Java 向Hbase表插入数据报(org.apache.hadoop.hbase.client.HTablePool$PooledHTable cannot be cast to org.apac
- 《计算机网络-自顶向下方法》之蜂窝网标准和技术
- 面试题
- 日经春秋 20151126
- 抽象类
- linux应用编程笔记(12)信号量详解及互斥编程
- 了解和防止内存泄露
- 【手把手教你全文检索】Lucene索引的【增、删、改、查】
- Tomcat配置可以上传文件的用户
- JS函数重载解决方案
- [Android学习笔记六] Toast 更长时间显示
- iOS Xcode, 解决“Could not insert new outlet connection”的问题
- 招聘一个靠谱的iOS 面试题参考