Skip to content

Instantly share code, notes, and snippets.

@luowei
Last active November 29, 2017 02:28
Show Gist options
  • Save luowei/aca6772da72dd15297191607edd4744d to your computer and use it in GitHub Desktop.
Save luowei/aca6772da72dd15297191607edd4744d to your computer and use it in GitHub Desktop.
更新强弱引用
//在主线程同步安全执行
#define dispatch_main_sync_safe(block)\
if ([NSThread isMainThread]) {\
block();\
} else {\
dispatch_sync(dispatch_get_main_queue(), block);\
}
//在主线程异步安全执行
#define dispatch_main_async_safe(block)\
if ([NSThread isMainThread]) {\
block();\
} else {\
dispatch_async(dispatch_get_main_queue(), block);\
}
// 过期提醒
#define WD_DEPRECATED(comment) __attribute__((deprecated(comment)))
#define WD_DEPRECATED_ATTRIBUTE __attribute__((deprecated))
#define WD_CLASS_DEPRECATED(comment) __attribute__((deprecated(comment)))
//强弱引用
#define weakify(var) __weak typeof(var) weak_##var = var;
#define strongify(var) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
__strong typeof(var) var = weak_##var; \
_Pragma("clang diagnostic pop")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment