Retrieve Information from txt File possible? - ios

I try to make my App as simple as possible. For this i want to store a .txt file with names on a Server and then populate a TableView with this txt. Inside the txt there should be just names, one at each line. Is it possible to get this txt into a tableview? I would use a plist file but the app will be updated by a person which is not used to programming and plist files.
Thanks for every answer.

You can read a simple textfile in whole into a NSString, split it by the linefeeds into a NSArray and there is your datasource for the tableview. You could make it editable with NSMutableArray instead, later convert it to NSString again and write it back to a file.

Related

Titles of .txt files saved locally are loading in random order in tableview - how to force a specific order?

I have a list of .txt files saved to Bundle and I list their titles to a tableview and load contents when row is clicked. I'm having a 2 fold issue.
1. The .txt files load randomly and in no particular order. I'm loading files like this right now:
func loadStories() {
stories = Bundle.main.urls(forResourcesWithExtension: "txt", subdirectory: nil)!
}
Is there a way to force a particular order for the list?
2. I'm also having a loading lag of a few seconds the longer the .txt file is and it was suggested that I should maybe convert my files to .xml instead to speed this up. Is this a good solution?
I'm also using firebase for authentication but as I understand it, firebase would not be a faster solution for files that are read only and not going to be changed. What can I do to help speed up the load?
1. The .txt files load randomly and in no particular order. I'm loading files like this right now:
I suppose stories is a collection (Dictionary / Array). Apply sorting in this array before reloading the UITableView
2. I'm also having a loading lag of a few seconds the longer the .txt file is and it was suggested that I should maybe convert my files to .xml instead to speed this up. Is this a good solution?
I think you are talking about the content of the files when showing details. You can add pagination in this case load part of the file (a few lines) show it. Then when further paged load further.
Example : Sorting on string objects in swift array as asked in comment:a
let months = ["JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"]
var sortedArray = months.sorted { $0.localizedCaseInsensitiveCompare($1) == ComparisonResult.orderedAscending }

Writing List of object into CSV File in xamarin.Android

Can any one suggest me How to implement writing List of objects into .csv into device download storage in c# xamarin android.The data exported to csv should be having headers.each item in list should be written in row .something similar to image attached
To create a CSV string, you'd generally do this manually. As an example:
string headers = $"{Column1},{Column2}";
string row1 = $"{row1.ValueA},{row1.ValueB}";
...etc...
Then append them together, separated by newlines. Obviously you'd be better off doing the above in some kind of loop.
As for putting it into android download storage, someone else will have to tell you how to do that, I don't know how!
i have followed below link http://www.joe-stevens.com/2009/08/03/generate-a-csv-from-a-generic-list-of-objects-using-reflection-and-extension-methods/ that helped me to implement.

Programmatically generated CSV file format issue for Excel and Numbers

In my iOS project, I have programmatically generated csv file from my data. Most of time, it looks all good for Microsoft Excel and Apple Numbers to open with.
But when the cell data is something like 5 - 60, it seems Excel would automatically convert it to date value like May-60, while Numbers open it correctly.
I have found this thread: https://stackoverflow.com/a/165052/833885, so the solution makes Excel happy is using "=""5 - 60""". But this will make Numbers shows ="5 - 60"......
You can quickly generate empty csv file to test what I described above.
Is is possible to generate csv file that makes all world happy???
Thanks in advance.
You can create a new file in excel and import from the data ribbon tab - this gives options to specify the data types for 'columns' in the csv. A bit of a pain but will avoid the issue.

Localization: Need English Version Only

I'm having trouble reading a NSLocalizedString through my English .csv file.
In my app a user comes across a UITableViewController and selects a row. Whatever that row's title is is set to a global NSString selectedRow inside a NSObject (this NSObject is imported in every class). Once this occurs the next UIViewController reads selectedRow, runs through the .csv file until it comes across it, and then vomits all the information needed onto the UIViewController.
Example: selectedRow = "About"; so in French this would be selectedRow = "Environ";
Now I don't have "Environ" in my .csv file, I have "About", so how would I force a NSLocalizedString to be English for a few moments without having to make a completely new French version of my .csv file?
If you want to use NSLocalizedString then you would need to make .string files, if your CSV is actually static and want to translate words like "About" then you can follow the instructions here to add the .string files, make one for English, one for French, then if the user is using French as the Language Setting, they will see the content in French... If your .csv is not static and it constantly changes and has full sentences, then this probably wont work, and you would probably want to use a french version of the .csv file... You can localize it as described above too..
Hope this helps
Daniel

How to get data from xml file on iOS

What I did on iOS is displaying grid of 10 images. For this I take a array and add all images to array. For this I am write the code as:
[_image addImage:[UIImage ImageNamed:#"black.jpg"]];
like this I add all images to array. Now what I need is to get all the images through Xml file and add to the images array. How can I do this?
The class you need is NSXMLParser and the delegate NSXMLParserDelegate.
Have a look here or even here at SO. What you are looking for is to parse an XML document, and you can do it with the NSXMLParser class, libxml2, or other libs/tools mainly based on those two. Also you'd better have a look at this project by Apple it will show you the main differences in terms of performance between technologies
First of all you need to parse your xml file. You can use the NSXMLParser class. How exactly you would do this, depends on the structure of your xml file. There are a lot of tutorials on the Internet about how to use it, for example see here.

Resources