How to check the NULL value in NSString in iOS?

前端 未结 10 1616
盖世英雄少女心
盖世英雄少女心 2021-01-02 15:17

I have an NSString and I want to check if it has a NULL value. If it does, then the if condition should execute. Else it should execut

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-02 16:09

    #define SAFESTRING(str) ISVALIDSTRING(str) ? str : @""
    #define ISVALIDSTRING(str) (str != nil && [str isKindOfClass:[NSNull class]] == NO)
    #define VALIDSTRING_PREDICATE [NSPredicate predicateWithBlock:^(id evaluatedObject, NSDictionary *bindings) {return (BOOL)ISVALIDSTRING(evaluatedObject);}]
    

    SAFESTRING("PASS_OBJECT_HERE");

提交回复
热议问题