IOS 开发中判断NSString是否为空字符

//当 请求网络 或者获取其他返回数据 首先 要做一次判断 数据是否为空 

防止程序崩溃 

程序崩溃 好比拿刀扎在程序员的心啊~

  

if(为空)
{
     做提示对话框等操作
}
else
{
     正常执行
}
 - (BOOL) isBlankString:(NSString *)string {//判断字符串是否为空 方法

    if (string == nil || string == NULL) {
        return YES;
    }
    if ([string isKindOfClass:[NSNull class]]) {
        return YES;
    }
    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
        return YES;
    }
    return NO;
} 

 

posted on 2014-02-12 17:10  ACM_Someone like you  阅读(1372)  评论(0编辑  收藏  举报

导航