ios - Get SwiftCSV Up and Running? -


i'm trying use swiftcsv naoty read .csv file. installed whole thing via cocoapods, when try use sample code github, sample "users.csv" file doesn't seem parse. in viewdidload() function, copied of sample code below. project builds , runs fine.

if let url = nsurl(string: "users.csv") {     var error: nserrorpointer = nil         if let csv = csv(contentsofurl: url, error: error) {             // 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"]          }      }  } 

users.csv:

id,name,age 1,alice,18 2,bob,19 3,charlie,20 

i added couple of println statements end of block. here's output, , output sample says should get.

println(headers)  

output: [ ] (should be: ["id", "name", "age"])

println(names)  

output: nil (should be: ["alice", "bob", "charlie"])

the line

let alice = csv.rows[0] 

also crashes application "fatal error: array index out of range" unless comment out. same bob.

what doing wrong?


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

php - Find a regex to take part of Email -

javascript - Function overwritting -