NSString is empty

前端 未结 8 1876
伪装坚强ぢ
伪装坚强ぢ 2021-01-30 05:45

How do you test if an NSString is empty? or all whitespace or nil? with a single method call?

8条回答
  •  爱一瞬间的悲伤
    2021-01-30 05:58

    I'm using this define as it works with nil strings as well as empty strings:

    #define STR_EMPTY(str)  \
        str.length == 0
    

    Actually now its like this:

    #define STR_EMPTY(str)  \
        (![str isKindOfClass:[NSString class]] || str.length == 0)
    

提交回复
热议问题