I need to get the hostname of a string url
I am trying to create the NSURL object from the string and then using host property of NSURL to get the host name. But Host name is always null.
NSURL *url = [NSURL URLWithString: @"www.google.com"];
NSLog(@"Host name %@", url.host);
but the host name is always null.
can anybody explain why is host name null?
Edit: I am sorry there was a typo i missed a quote and a comma while asking the question. But the problem is still the same.
As per Apple documentation,
Return Value:
So if it is not conforming to
RFC 1808, it will return nil. As per definition ofRFC 1808,correct syntax is as follows :
So you need to add
http://also while formingNSURL.