func getDataFrom(UrlString : String) -> String?{
let Url = URL (fileURLWithPath: UrlString)
do{ let _ = try Data(contentsOf: Url) return "success" }catch{ print(error) return "fail" } } if let data = getDataFrom(UrlString: "http://www.baidu.com"){ print(data) }報(bào)錯(cuò)
Error Domain=NSCocoaErrorDomain Code=260 "The file “www.baidu.com” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/xxx/Library/Developer/Xcode/DerivedData/DownloadWallpaper-fhscltsqxkthirfdumcybcadbkna/Build/Products/Debug/http:/www.baidu.com, NSUnderlyingError=0x100e072e0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
fail
Program ended with exit code: 0