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

swift2 loading contents of text file into variable

我试图通过从文本文件加载数组然后用换行符分隔文本来构建数组来填充数组,但是我收到错误 "Expected Expression"

  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