解决方法
不幸的是,NSURL不会告诉您URL创建失败的原因.
在NSURL上执行ALT CLICK时从Xcode弹出窗口中:
Handling Object Creation Failure
The NSURL class fails to create a new NSURL object if the path being passed is not well formed; the path must comply with RFC 2396. Examples of cases that will not succeed are strings containing space characters and high-bit characters. If creating an NSURL object fails,the creation methods return nil,which you must be prepared to handle.
因此如果失败,NSURL将返回nil,而不提供任何进一步的细节.通常使用可选绑定,可选链接,防护或任何其他已知技术来安全地解包选项,并遵循Fogmeister的建议并在使用前对URL字符串进行编码.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。