The URL string with which to initialize the NSURL object. Must be a URL that conforms to RFC 2396. This method parses URLString according to RFCs 1738 and 1808.
Return Value
An NSURL object initialized with URLString. If the URL string was malformed or nil, returns nil.
文档里提到string 的格式必须复合RFC 2396,解析按照RFC 1738和1808来进行解析
参考链接:
http://zh.wikipedia.org/zh-cn/统一资源标志符
网址必须是
http://
开头的噢NSURL *URL = [NSURL URLWithString:@"http://www.baidu.com"];
不接受汉字,需要先转换成utf8……
(这个是不是太白痴了)
NSURL会返回nil如果你的格式有错误。
只有在格式规范的条件下才会创建一个有效的NSURL类型
参见官方文档
Parameters
The URL string with which to initialize the NSURL object. Must be a URL that conforms to RFC 2396. This method parses URLString according to RFCs 1738 and 1808.
Return Value
An NSURL object initialized with URLString. If the URL string was malformed or nil, returns nil.