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中已弃用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)