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

前端 未结 9 757
盖世英雄少女心
盖世英雄少女心 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:32

    My simple coding for you

     let path = NSBundle.mainBundle().pathForResource("FileName", ofType: "txt")
     var text = String(contentsOfFile: path!, encoding: NSUTF8StringEncoding, error: nil)!
     println(text)
     var array = text.componentsSeparatedByString("\n")
    

提交回复
热议问题