gpt4 book ai didi

ios - swift2 将文本文件的内容加载到变量中

转载 作者:行者123 更新时间:2023-11-30 13:35:11 25 4
gpt4 key购买 nike

我试图通过从文本文件加载数组来填充数组,然后用换行符分隔文本以制定数组,但是我收到错误“预期表达式”

  var marrCountryList = [String]()
try! var text = String(contentsOfFile: "country", encoding: NSUTF8StringEncoding)
marrCountryList = text.componentsSeparatedByString("\n")

最佳答案

try 位置不正确:

do {
contentsOfFile = try String(contentsOfFile: "country", encoding: NSUTF8StringEncoding)
} catch {
print(error);
contentsOfFile = nil;
}

此外,当您使用 try 时,您必须有 docatch

关于ios - swift2 将文本文件的内容加载到变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36166583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com