Read a text file line by line in Swift?

前端 未结 6 734
广开言路
广开言路 2020-12-05 04:14

I just started learning Swift. I have got my code to read from the text file, and the App displays the content of the entire text file. How can I display line by line and ca

6条回答
  •  孤城傲影
    2020-12-05 04:41

    You probably do want to read the entire file in at once. I bet it's very small.

    But then you want to split the resulting string into an array, and then distribute the array's contents among various UI elements, such as table cells.

    A simple example:

        var x: String = "abc\ndef"
        var y = x.componentsSeparatedByString("\n")
        // y is now a [String]: ["abc", "def"]
    

提交回复
热议问题