I have to access a web server using a GET
with international characters (Hebrew in my case but could be anything).
So I make an NSString
just fine but
[NSURL URLWithString:urlString]; // returns nil.
I realize I probably have to convert the international characters to percent codes.
Is there a built in method in Objective-c to do so?
Yes there is, you need
-stringByAddingPercentEscapesUsingEncoding:
method:You can use
NSURL
directly withoutNSString
:Just pass a
NSURL
from another view (usingNewsUrl
variable) to this view.This would ensure
NSURL *url
does not returnnil
because of the"|"
in theurlString
.calling this function instead of URLWithString: should ensure that a valid NSURL is always returned (instead of nil when needed)