ios 确保NSUrl不为nil

1.先去空格

NSString *urlString = @"http://sfsdfsdfsd sdfsdfsfsdf你好";

urlString = [urlString stringByReplacingOccurrencesOfString:@" "withString:@""];

2.转码

urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

3.转成NSUrl

NSURL*url = [NSURL URLWithString:urlString];

你可能感兴趣的:(ios 确保NSUrl不为nil)