如何在Objective-C中测试字符串是否为空?
- 论坛
- 如何在Objective-C中测试字符串是否为空?
41 浏览
匿名的
0 Comments
马克的答案是正确的。但我想借此机会提供一个指向威尔·希普利通用的isEmpty
的指针,他在他的博客上分享:
static inline BOOL IsEmpty(id thing) { return thing == nil || ([thing respondsToSelector:@selector(length)] && [(NSData *)thing length] == 0) || ([thing respondsToSelector:@selector(count)] && [(NSArray *)thing count] == 0); }