Go to file
Yasuhiro Hatta 0acd6ddd20 Fix compiler warning 2016-08-21 11:32:27 +09:00
CSV.xcodeproj Update .xcodeproj 2016-07-11 22:18:34 +09:00
Sources Fix compiler warning 2016-08-21 11:32:27 +09:00
Tests Apply the UpperCamelCase to enums 2016-07-23 13:25:39 +09:00
.gitignore Initial commit 2016-06-11 02:10:59 +09:00
.travis.yml Version 0.3.0 2016-07-23 13:06:03 +09:00
CSV.swift.podspec Update podspec 2016-08-21 11:21:32 +09:00
LICENSE Initial commit 2016-06-11 02:10:59 +09:00
Package.swift Add Package.swift 2016-06-11 12:08:43 +09:00
README.md Update README.md 2016-08-21 11:21:49 +09:00

README.md

CSV.swift

Build Status

CSV reading library written in Swift.

Usage

From CSV string

import CSV

for row in try! CSV(string: "1,foo\n2,bar") {
    print("\(row)")
    // => ["1", "foo"]
    // => ["2", "bar"]
}

From file path

import CSV

let stream = NSInputStream(fileAtPath: "/path/to/file.csv")!
for row in try! CSV(stream: stream) {
    print("\(row)")
}

Getting the header row

let csv = try! CSV(
    string: "id,name\n1,foo\n2,bar",
    hasHeaderRow: true) // default: false

let headerRow = csv.headerRow!
print("\(headerRow)") // => ["id", "name"]

for row in csv {
    print("\(row)")
    // => ["1", "foo"]
    // => ["2", "bar"]
}

Get the field value using subscript

let csv = try! CSV(
    string: "id,name\n1,foo",
    hasHeaderRow: true) // It must be true.

while csv.next() != nil {
    print("\(csv["id"]!)")   // => "1"
    print("\(csv["name"]!)") // => "foo"
}

Provide the character encoding

If you use a file path, you can provide the character encoding to initializer.

let csv = try! CSV(
    stream: NSInputStream(fileAtPath: "/path/to/file.csv")!,
    codecType: UTF16.self,
    endian: .Big)

Installation

CocoaPods

pod 'CSV.swift', '~> 0.3'

Carthage

github "yaslab/CSV.swift" ~> 0.3

Swift Package Manager

import PackageDescription

let package = Package(
    name: "PackageName",
    dependencies: [
        .Package(url: "https://github.com/yaslab/CSV.swift", majorVersion: 0, minor: 3)
    ]
)

Reference specification

License

CSV.swift is released under the MIT license. See the LICENSE file for more info.