1

Actually Iam trying to create NSUrl From string which comprises of english as well as arabic words with spaces.but the NSURl returns null after passing this to nsurl. what should i do to get this done.

2 Answers2

2

you should do like this: second line is important.

NSString *urlstr=[NSString stringWithFormat:@"www.ModelAirplane.ir/هاشم"];

urlstr = [urlstr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURL * url=[NSURL URLWithString:urlstr];
NSLog(@"%@",url.description);
Hashem Aboonajmi
  • 13,077
  • 8
  • 66
  • 75
2

Use this in Swift 2.0

let  = "http://example.ir/اسم-عربي"
let safeURL = urlStr.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!

reference from here

Community
  • 1
  • 1
Husam
  • 8,149
  • 3
  • 38
  • 45