Parsing a .CSV file

Discussion in 'iOS Programming' started by James83448, Aug 26, 2015.

  1. James83448 macrumors regular

    James83448

    Joined:
    Jun 4, 2015
    #1
    Sorry if this thread is in the wrong board, I couldn't find a board specially for iOS development.

    I've very recently got into iOS development with Swift, and I'm looking into writing an app that overlays points of interest, onto a map.

    I've got the data set downloaded, although I'm not sure how I can parse this set so that I can create an object for each data entry?

    I can get a copy of the file in either .CSV, .KML or .JSON.

    Can anybody suggest any method of parsing the file into a swift file?
     
  2. recoil80 macrumors 68000

    Joined:
    Jul 16, 2014
    #2
    You mean parsing the file into a Swift data structure.
    If you can have a JSON you'll be able to parse it via the API NSJSONSerialization.JSONObjectWithData and you'll get an array or a dictionary (I suppose it will be an array).
    If you prefer a CSV you'll have to parse it yourself by splitting the file into strings separated by \n\r then get each field by splitting each line with , or ; or | or whatever is used in the CSV.
    Using a JSON is more straightforward, but the file size might increase.
     
  3. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #3
    I haven’t looked at this closely, it just came up in a search; A KML viewer sample app at Apple may be of help to you. It’s Objective-C but it could be a guide. It is using Mapkit too.

    For handling CSV files, take a look at integrating CHCSVParser (and CHCSVWriter). Yet again, Objective-C code.
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
  5. sziehr macrumors 6502a

    Joined:
    Jun 11, 2009
    #5
    not to high jack but i am working on a JSON pull from a weather API and i have an array of any objects and casting them is seeming almost impossible. I am using swift 2.0.

    I can pull the JSON data down but i and dump it to the console but that data is not in a format i can use to push to a table or label. I have tried to cast them as! NSDictonary and it works but the output subunit is still an any object and I can not for the life of me get that into a String nor NSString.

    I would be happy to dump in some code here if you cause would not mind taking a gander. I am sure i am overlooking something pretty simple or minor change from 1.0 to 2.0
     
  6. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    I think you should start your own thread for this. They're free.
     
  7. sziehr macrumors 6502a

    Joined:
    Jun 11, 2009
    #7
    thanks phoneydev lol. It just seemed to be we were working a similar vane on parsing with JSONSerialized I will start my own lonely thread about my pain of using the built in JSON Parsing engine
     

Share This Page