#define isEmptyString(string) \
({\
NSString *resultStr = [string length] ? string : @"It's empty";\
(resultStr);\
})\
使用:
NSString *str1 = @"12345";
NSString *str2 = @"";
NSString *str3 = nil;
NSLog(@"str1 = %@,\n str2 = %@, \n str3 = %@,\n", isEmptyString(str1), isEmptyString(str2), isEmptyString(str3));
打印结果:
str1 = 12345,
str2 = It's empty,
str3 = It's empty,
该宏定义作用:
空字符串返回It's empty,非空字符串返回自身。