How do I load a text file line by line into an array with Swift?

前端 未结 9 792
盖世英雄少女心
盖世英雄少女心 2020-12-29 18:51

How do I load a text file line by line into an array with swift?

9条回答
  •  没有蜡笔的小新
    2020-12-29 19:28

    For me works as follow:

    let myFileURL = NSBundle.mainBundle().URLForResource("listacomuni", withExtension: "txt")!
    let myText = try! String(contentsOfURL: myFileURL, encoding: NSISOLatin1StringEncoding)
    print(String(myText))
    

提交回复
热议问题