ios - Create NSURL with string containing "^" character gives a nil -


when try creating nsurl string containing "^" character app crashs , console says:

fatal error: unexpectedly found nil while unwrapping optional value 

does faced before ?

edit:

it seems nsurl initializer gives nil object, , app crashs when trying enforce unwrapping it.

how can avoid getting nil instance of nsurl string containing such character?

edit

here code, clarify things:

let searchmethod = "advancedsearch.php?" let searchparameters = "q=title:book^100%20or%20description:book^15%20or%20collection:book^10%20or%20language:book^10%20or%20text:book^1&mediatype:texts+and+not+hidden:true+and+collection:texts&sort%5b%5d=titlesorter+asc&rows=10&output=json&start=1" nsurl(string:"\(baseurl)/\(searchmethod)\(searchparameters)") print("url \(url)") 

the nsurl nil,console gives :

url nil 

"^" symbol not allowed url encoding.
use 1 swift:

let encodedurlstring = urlstring.stringbyaddingpercentencodingwithallowedcharacters(.urlhostallowedcharacterset()) 

or objective-c:

nsstring *encodedurlstring = [urlstring stringbyaddingpercentencodingwithallowedcharacters:[nscharacterset urlhostallowedcharacterset]]; 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -