Правильный формат для замены пробела из URL:
Цель C
NSString *urlString;//your url string.
urlString = [originalUrl stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
или
urlString = [originalUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
iOS 9 и более поздние версии
urlString = [originalUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
Swift:
var originalUrl = "https://google.com"
var urlString = originalString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
ios 9 и более поздние версии
var urlString :String = originalUrl.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!
Swift 4
var urlString = originalString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)
Swift 4.2
var urlString = originalString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)