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?
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
There is a string feature that will take each value and place it into an array:
NSArray *anArray = [yourString componentsSeparatedByString:#","];
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.
Related
I'm working on a RoomPlan app. I've successfully managed to capture, save and load scans using NSKeyedArchiver. However, for apps run on the simulator or on devices without a LiDAR Scanner, I do not have any scans saved on that device so I cannot test the functionality. I want to "fill" my app with a test scan or two to be able to test my app on those devices.
The core problem here is that I can't figure out how to "capture" objects in Swift and save them hardcoded in the app instead of in NSKeyedArchiver, which is local to every device.
You are doing this:
RoomScan --(via NSKeyedArchiver/Encodable)--> Data --(save)--> UserDefaults
UserDefaults --(read)--> Data --(via NSUnarchiver/Decodable)--> RoomScan
So, what I suggest:
Scan a room, then convert it as Data, save it if needed.
Intercept that Data either by forcing a reading, or before saving into UserDefaults.
Choose the solution you find easier/quicker for you for the "intercept":
Convert the Data into HexString (see How to convert Data to hex string in swift), print it into Console, copy the output or save maybe that content into a Data file, and send it via AirDrop/Mail.
Create a new file into your project, and read it when needed (simulator, etc). Depending on the solution chosen since the writing might differ, the reading also might differ.
I have Excel file with table ~100x100 and need to get access to this values from iOS app.
At first, I've try to make json in Mr.DataConverter and then it's not a problem to read to array. But! Some float values didn't recognized properly, and I'd got numbers without quotes:
At the time other parsed correctly!
So, from this moment I can't parse my Json string to NSArray.
The question is:
How to convert xls to json, OR How to put and retrieve the values in iOS device?
Thanks.
You can use the DHlibxls iOS Framework and simply pull the .xls file into your app, then read and process with that framework. The framework is based on the open source libxls library on SourceForge, and has a non-attributed BSD license.
I recommend exporting the Excel spreadsheet to CSV and then using a proper CSV parser to parse the data. If you run into any issues then there is likely an issue in the spreadsheet that you would need to fix.
Alternative: If possible use excel file in formate: tab delimited-text-file. That solve all your problem. Easy to open text file in iOS with file manager/c++.
convert-an-excel-spreadsheet-to-a-tab-delimited-text-file
I have seemingly a lot of text that i need to get into my iphone app. It's not nearly as much as a book or anything but it would take quite some time to type it all out in xcode, and I'm sure thats not the best way. I read you can import an xml file or maybe a .txt, could someone please point me in the best direction, and maybe a tutorial or something to help me get started?
Thanks!
You can bundle any file you want with your application as a resource. Just include it as part of your project, and then you can load it in your app as an NSString* or NSData*, whichever your prefer/whichever is most appropriate to your data type.
You can also transform the data however your would like, and write some new file that contains the transformed information, and then grab the new file and package that one with the app so that the transformation step no longer needs to be run. For instance, maybe you want to parse your text data and prepopulate a Core Data model with it. You could write the code that does this, grab the .sqlite database file that is generated, and then package the database file in the deployed version of your app so that everyone starts out with an already-populated data model. If that happens to be your use-case here.
What you mean by get text into my iphone app? Do you want to show the text in your application? If yes, why don't you just use the this NSString method:
+ (id)stringWithContentsOfFile:(NSString *)path
encoding:(NSStringEncoding)enc
error:(NSError **)error
If your text needs to be formatted, I would recommend you to use webview to load formatted html files.
I save XML file in Resources folder in xcode. And I parse it when application launches and use it for a default data set. I don't see any problem with this but people are talking about CoreData to handle a default data set. Can I just still use XML file for a default data? what is the disadvantage of using XML for default data set?
I'd say you're fine using an XML file, assuming that the data is small and you're not modifying it a lot. I use a CSV file for a couple of my apps and that's worked fine for me.
With that said, here are better answers to a similar question: Plist vs SQLite vs Core Data for a rss reader type application?
I'm working on an app and need to add the ability to import CSV files into the app for processing. What are the options here? I've read posts about embedding http servers or fetching a CSV file from a web resource, but what is the easiest way to do this?
thanks
I've used NSData's dataWithContentsOfURL: just recently; it worked fine. Plus there's a convenient writeToFile:atomically: or writeToFile:options:error: message you can send to your data object.