6
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Swift3.0】 CSVから読み込んで、配列にする

Last updated at Posted at 2016-11-17
Swift3.0
func csvToArray () {
   if let csvPath = Bundle.main.path(forResource: "ファイル名を記入", ofType: "csv") {
      do {
         let csvStr = try String(contentsOfFile:csvPath, encoding:String.Encoding.utf8)
         let csvArr = csvStr.components(separatedBy: .newlines)
         print(csvArr)
      } catch let error as NSError {
         print(error.localizedDescription)
      }
   }
}

改行を基に分割して配列にしています。

追記:ご指摘ありがとうございます

6
11
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?