Swift3.0 文件写入时 no scheme

前言

在使用Swift进行文件读取时系统输出错误: CFURLCopyResourcePropertyForKey failed because it was passed an URL which has no scheme. Error Domain=NSCocoaErrorDomain Code=518 "The file couldn’t be saved because the specified URL type isn’t supported."

原因

查看相关源文件

Swift3.0 文件写入时 no scheme_第1张图片
Data

url必须是一个本地位置,所以需要使用本地文件传输协议 File Protocol

解决

  • var filePath = "file://(fileURLpath)"
  • var url:URL = URL.init(fileURLWithPath: str)

参考链接

CFURLCopyResourcePropertyForKey failed because passed URL no scheme

你可能感兴趣的:(Swift3.0 文件写入时 no scheme)