[英]Cannot get contents of URL
So I have the following URL: 所以我有以下URL:
let theURL : NSURL = NSURL(string: "http://www.iana.org/domains/example")!
But all I get after running: 但是我跑步后得到的一切:
let blob : String
do {
blob = try String(contentsOfURL: theURL)
}
catch {...}
Is a console statement that reads as follows: 是一个控制台语句,内容如下:
CFURLCopyResourcePropertyForKey failed because it was passed an URL which has no scheme CFURLCopyResourcePropertyForKey失败,因为它传递了没有方案的URL
The URL is valid, and the code works with: 该URL有效,并且该代码可用于:
What am I doing wrong? 我究竟做错了什么?
Here's a cleaner version of what you're trying to do. 这是您要执行的操作的更简洁的版本。
let theURL = NSURL(string: "http://www.iana.org/domains/example")!
let blob : String
do {
blob = String(theURL)
}
catch { }
Corrections: 更正:
I'm not sure what you're trying to accomplish, but if you provide me with more information I can better answer your question. 我不确定您要完成什么,但是如果您向我提供更多信息,我会更好地回答您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.