SwiftCSVCSV 解析器封装
SwiftCSV 是 CSV 解析器封装。
用法:
id,name,age 1,Alice,18 2,Bob,19 3,Charlie,20
访问行和列的数据:
let csvURL = NSURL(string: "users.csv") let csv = CSV(contentsOfURL: url) // Rows let rows = csv.rows let headers = csv.headers //=> ["id", "name", "age"] let alice = csv.rows[0] //=> ["id": 1, "name": "Alice", "age": 18] let bob = csv.rows[1] //=> ["id": 2, "name": "Bob", "age": 19] // Columns let columns = csv.columns let names = csv.columns["name"] //=> ["Alice", "Bob", "Charlie"] let ages = csv.columns["age"] //=> [18, 19, 20]
评论