dataWithContentsOfMappedFile在iOS 8.0中已弃用

dataWithContentsOfMappedFile在iOS 8.0中已弃用,第1张

概述我使用以下代码从 JSON文件中检索数据. let jsonData = try NSData.dataWithContentsOfMappedFile("/Users/User/Desktop/Employee.json") 我收到以下错误 dataWithContentsOfMappedFile was deprecated in iOS 8.0: Use +dataWithContentsO 我使用以下代码从 JSON文件中检索数据.

let JsonData = try NSData.dataWithContentsOfMappedfile("/Users/User/Desktop/Employee.Json")

我收到以下错误

dataWithContentsOfMappedfile was deprecated in iOS 8.0: Use +dataWithContentsOfURL:options:error: and NSDataReadingMappedIfSafe or NSDataReadingMappedAlways instead

有人可以让我知道替代方案吗?

解决方法 试试这个

从本地路径获取使用contentsOffile否则使用contentsOfURL

let contents: NSData?    do {        contents = try NSData(contentsOffile: "/Users/User/Desktop/Employee.Json",options: NSDataReadingOptions.DataReadingMappedAlways)    } catch _ {        contents = nil    }    print(contents)

如果您只想访问contentsOffile,请使用以下行

let contents   =  NSData(contentsOffile:"/Users/User/Desktop/Employee.Json")     print(contents)
总结

以上是内存溢出为你收集整理的dataWithContentsOfMappedFile在iOS 8.0中已弃用全部内容,希望文章能够帮你解决dataWithContentsOfMappedFile在iOS 8.0中已弃用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1048083.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存