美文网首页
iOS-好用的宏定义(判断是否为字符串、数组、字典、判断是否继续

iOS-好用的宏定义(判断是否为字符串、数组、字典、判断是否继续

作者: 贵叔勇闯天涯 | 来源:发表于2020-06-29 17:30 被阅读0次

判断是否为字符串、数组、字典

#define __IsStringValid(_str) (_str && [_str isKindOfClass:[NSString class]] && ([_str length] > 0))
#define __IsArrayValid(_array) (_array && [_array isKindOfClass:[NSArray class]] && ([_array count] > 0))
#define __IsDictionaryValid(__dic) (__dic && [__dic isKindOfClass:[NSDictionary class]] && ([__dic count] > 0))

判断是否继续、安全字符串(没有的为空)、weak_self

#ifndef guard
#define guard(CONDITION) \
if (CONDITION) {}
#endif

#ifndef SAFESTR
#define SAFESTR(x) ((x) ?: @"")
#endif

#ifndef WEAK_SELF
#define WEAK_SELF __weak typeof(self) __dg_weakSelf = self;
#endif

#ifndef STRONG_SELF
#define STRONG_SELF      \
__strong typeof(__dg_weakSelf) self = __dg_weakSelf;
#endif

#ifndef STRONG_SELF_AND_RETURN_IF_NULL
#define STRONG_SELF_AND_RETURN_IF_NULL      \
__strong typeof(__dg_weakSelf) self = __dg_weakSelf;  \
if (!self) { return; }
#endif

相关文章

网友评论

      本文标题:iOS-好用的宏定义(判断是否为字符串、数组、字典、判断是否继续

      本文链接:https://www.haomeiwen.com/subject/smhofktx.html