How to check the NULL value in NSString in iOS?

前端 未结 10 1534
盖世英雄少女心
盖世英雄少女心 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:06

    +(BOOL)isEmpty:(NSString *)str{
        if (str == nil || str == (id)[NSNull null] || [[NSString stringWithFormat:@"%@",str] length] == 0 || [[[NSString stringWithFormat:@"%@",str] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0){
            return YES;
        }
        return NO;
    }
    

    Just pass your string in Method :)

提交回复
热议问题