加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在swift中读取一个短文本文件到一个字符串

发布时间:2020-12-14 05:42:17 所属栏目:百科 来源:网络整理
导读:我需要在我的Swift程序中阅读一个短文本文件的内容.我做到了 var err: NSError?let bundle = NSBundle.mainBundle()let path = bundle.pathForResource("cards",ofType: "ini")let content = String(contentsOfFile: path!,encoding: NSUTF8StringEncoding,e
我需要在我的Swift程序中阅读一个短文本文件的内容.我做到了
var err: NSError?
let bundle = NSBundle.mainBundle()
let path = bundle.pathForResource("cards",ofType: "ini")
let content = String(contentsOfFile: path!,encoding: NSUTF8StringEncoding,error: nil)

我的问题是我不能使用错误报告.如果我将最后一行更改为:

let content = String(contentsOfFile: path!,error: err)

编译器抱怨“额外的参数”contentsOfFile’在调用“.这对我来说是零感的,也许别人可以弄清楚吗?

乍一看我会说你必须通过引用传递err变量:
let content = String(contentsOfFile: path!,error: &err)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读