iPhone app that reads .csv file

14,870

Solution 1

You can read CSV data but "place the file on the device" would have to involve a web service of some sort. There is no way to add data to an application without getting in a from a web server. But if you have a web server that can host the csv file then opening and reading it is fairly simple.

this covers most o it Import csv data (SDK iphone)

NSString stringWithContentsOfURL:encoding:error

will take care of the rest

Solution 2

There is a string feature that will take each value and place it into an array:

NSArray *anArray = [yourString componentsSeparatedByString:@","];

Solution 3

You can parse CSV on an iOS device. You can place a data file on an iOS device.

Beware though of CSV format details. Just splitting a string on "," is a surefire way to get failures and random errors. Have a look at http://cocoawithlove.com/2009/11/writing-parser-using-nsscanner-csv.html for a good example on how to handle CSV data.

I've personally used the example from cocoa with love to create an operation that downloads a CSV from a http location, parses and processes it and then stores the results in a Core-Data store.

But you could just as well get the CSV file on your device by using an NSURLConnection. Beware though: NSURLDownload is unavailable on iOS. Also downloading data to the device is not recommended. Apple recommends processing the data and storing the results or just getting the data as you need it.

Share:
14,870
TheLearner
Author by

TheLearner

Updated on June 04, 2022

Comments

  • TheLearner
    TheLearner almost 2 years

    Can an iOS app read a file that has been placed on that device e.g. a CSV file.

    So the idea is when you're at home you create the file with a list of items or you get emailed it etc on your PC and then you place this file (in the correct format) on the device which reads it.

    Is this possible?

  • TheLearner
    TheLearner about 13 years
    Thanks. Do you know of any free web services that allow sporadic updating of CSV files or something similar. I want my app users to be able to update the list when they on their PCs and then the app reads it.
  • hatunike
    hatunike almost 12 years
    Techinically, you don't need a web service to place a CSV file on the iphone. The app could generate the CSV file using data that it creates. Also, you can add files through itunes without a web server, but I have to agree that 99% of the time CSV files involve servers.