UTF-8 string encoding (Swift)

By | March 23, 2015

Let’s assume you have a human-friendly string and you want to make it a part of url. It’s not that hard:

  var baseUrl : String = "http://example.com/place/"
  var name : String = "GALERIA DOMINIKAŃSKA"
  var encodedName = name.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
  var finalUrl = baseUrl + encodedName
  // println(finalUrl)
  // http://example.com/place/GALERIA%20DOMINIKA%C5%83SKA

 

Leave a Reply