I want to ship my app with a built-in FAQ on the settings page. The FAQ is simple:
1) We have a table view which lists all the questions. One per cell.
2) When the user taps one of those questions, we slide over to a detail view controller which shows the question in bold letters and then the answer. Very simple.
The hard part: What would be the optimal way to feed the table view and detail view controller with the strings?
Bad ideas (from my point of view):
Hardcode all strings and work with giant if or switch monsters.
Rely on NSLocalizedString() to fetch the localized version of an answer. Those strings files don't look like they were intended for very large strings. Just for a few sentences or words per line. With tons of FAQ text those strings files would become horrifying.
This is how I'd attempt to do it, but you may suggest a better way:
Solution 1)
Create an JSON file where entities have three fields: ID, Question and Answer. ID will help us track down which Answer we have to load after the user tapped a cell.
Localize that JSON file.
When the table view loads, read it into memory and parse it, just to read out the questions and ID's (yes, less than ideal, right?)
When the user taps a cell, either pass the ID just to re-fetch the whole thing again, or maybe better: Pass the ID, question and answer strings to the details view controller.
Solution 2)
Like 1, but use Core Data instead. Probably better for memory and performance, but probably harder to maintain (must mess around with a SQLite3 file to build the FAQ, needs at least a good IDE to do that to not go crazy). Caveat: Can't pass it to translators easily. Tons of manual work just to create that SQLite3 file. Files localized in localization folders.
Solution 4)
Two splitted JSON files: One with all the ID's and Questions. Another with all the ID's and Answers. Files localized in localization folders.
Solution 5)
An JSON file with all the IDs and Questions. For every ID, there's a matching Answer text file. So we don't end up loading tons of data into memory just to extract some tiny fraction of it.
Solution 6)
Use something that already exists, or a different approach. Suggestions?
Normally, you would localize a localizedStrings-file, so that they can get translated when you run NSLocalizedString. What you may not know is that this basically works for all kinds of files, so plists too:
Create a localized faq plist-file.
Request it (from in the app) with [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"faq" ofType:#"plist"]];
Implement it in your UITableView. (- (NSInteger)numberOf... => return [faq count];).
Oh, and I use a plist-file instead of JSON or XML since Apple uses it, since it's really easy to implement (NSArray - arrayWithContentsOfFile is built in) and you can maintain it very easily in Xcode.
Related
Ive tried to search up documentation and several tutorials but it seems like there's nothing out there. Maybe this is something simple to do, but I just cannot figure it out.
My goal is to make an application that has a series of questions that you fill in. Some tick boxes and some text fields where you fill in some more info. This survey would be on one VC and you scroll down through the questions. After all this I want to append the data to the apple numbers app on the iPad with a specific structure.
How would I go about this? Any resources you can recommend?
T.I.A
I believe that you should generate and export a .csv file with all the data you collect in the app. Save that file to iCloud Drive or to another cloud solution you can integrate in your app, and then access it and open it using Numbers.
How does this sound conceptually.
I wanted to store some text and add tags to it thats easily retrivable. Coredata is the obvious solution, but i also needed that data across the cloud, not just iCloud like dropbox. So I thot i'd use Coredata + textFiles.
obvious approach
use coredata with two entities. One for text and one for tags. Works awesome BUT not ready for syncing.
1. using icloud coredata combo will hurt me badly, its still unreliable, and i cant afford to keep stabilising it.
2. i dont just have ios devices, need it on my computer too.
the solution
Add text in a simple textview.
Add tags to the text as well using some kinda delimiters.
Save the document as a text file (that includes tags) and give the document some unique name
Put that file in dropbox or icloud or whatever as a document But Also, parse it locally in the iOS app so that the text in file is separated into text and tags each of which enters its entity in coredata.
advantage for the solution
I can use the text in a useful way locally (in iphone) and if needed will get those text files from the cloud.
problem with the solution
Data in the cloud (as textfiles) is only so useful. But nonetheless, its there, i can live with this.
SYNCING: how do i make sure that each file is synced appropriately. Im not sure I should use UIManagedDocument? I'm already using coredata locally, dont know how i'd complicate things if i use UIManagedDocument.
My question is, im confused about the syncing and saving part, what should i do to keep it neat and clean.
While writing this question i feel like I screwed up the whole idea.
any recommendations for saving four strings into an own file format that is read by the application and can be shared?
In my app, you will be able to enter some text in some boxes and the app shows a view with an background image and those strings. Now, I am already able to save this as a picture, but I actually want to save it to an own file format so that you can save different files that can be modified afterwards as well or even exchanged via email and opened from another iphone with the app.
Now, I wrote the code for accessing the documents folder of the app, as well as saving and deleting. Thing is, i dont know how to store those strings in a file (perhaps in a xml?) and read them easily afterwards from my application.
For the exchanging part, I found that link which would be a nice feature indeed: http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
Parsing xml seems not that difficult (never done it before): http://ipad.about.com/od/iPad-App-Dev/a/How-To-Parse-Xml-Files-In-Xcode-Objective-C.htm
If it's only a small bit of infomation then the easiest way to store your data in a file would be using a plist - there's a good tutorial here - http://www.icodeblog.com/2009/02/14/loading-data-from-plist-files/
In addition to the plist, you could also do the following approaches:
1) simplest - open a file in your documents directory, write the 4 strings (using whatever delimiter/end of string marker is useful - carriage return?) and overwrite them each time through. (i.e. it's your file, you can format it how you like)
2) mildly harder - use Apple's NSArchive to pack and unpack the strings.
3) possible overkill - store them directly in a SQLite database
4) major overkill - store them in CoreData.
Of course, the "overkill" options also provide you with extra features which may be of use if your app functionality extends beyond what you've outlined.
By sharing, I would think that simple copy and paste might be enough, but there's also sending it via email, or tripping another app's URL scheme to make it open it and sending the strings as part of the URL. You'd have to know that the other app would be able to interpret your strings as part of the URL, so you might have to write it yourself.
Okay guys I found that very nice method in the NSString documentation:
–writeToFile:atomically:encoding:error:
I think I am gonna separate my strings by /n and save them to a .txt. When I am gonna read the file afterwards, i am getting the string, divide it to substrings. That will do it, I guess.
One last question: Is it possible to replace the content of my file so that I won't need to create a new file every time i want to change something?
Thanks!
I seem to have a misunderstood some concepts about data management after reading the docs. So Im trying to clarify some aspects. Apologize if this post sounds redundant and repetitive.
My app has multiple TableViews. Each tableview has a datasource in the form of a pList.
I thus have several propertylists that serve as the data sources for my tables. Currently, they are sitting within my NSBundle. And I read data from them and initiate an array or dictionary to populate my tables
NSString *pathToPlist = [[NSBundle mainBundle]
pathForResource:#"TableViewDataSource" ofType:#"plist"];
TableDSource = [[NSArray alloc]initWithContentsOfFile:pathToPlist];
Now, I want to keep content within my tableView dynamic. What I mean is say the tableView for example contains a list of items for sale, In about a month the business owner might decide to change that list or the prices of the items, etc. When I ship my app, the items for sale which are in the pList are shipped also shipped with the app.
How then do I update that property list at a later time after someone has downloaded the app? Do I have to issue a new release of the app each time any data within the app has changed?
or can I program right from the beginning in such a way that the pLists are dynamic and new ones can replace old ones without updating the app?
Please help me understand this, im not gettig how that works.
Thanks
The general mechanism is that you would copy the plist out of the bundle into somewhere you can write to (like the Documents directory). You would then have updated lists on a web site that the app would check for, when it found a new one it would download it and replace the existing plist file.
Sweet..I bought myself a 1TB portable harddrives this week. Don't you just love how much data you could store on one of these disks? The fact that I could store my bluray rips on to my portable harddisk and that my lg lcd tv can do HD rips right from the drive - that's amazing practicality right there! However, life it seems, is never so simple. I have 100s of movies unorganized in one huge folder, which is exactly what I needed to annoy myself while browsing the same on my tv to play a single movie. That got me thinking...
What if I had an automated way to organize movies into folders such that my folder-browsing-on-a-lcd-tv-or-a-comp would make my life a little easy?
I started thinking about this... I browsed a little in this context and I realized that if only I could "tag my movies somehow and create folders on-the-fly based on tags using hardlinks", I would have addressed my problem. I googled a bit to find software that works in the above fashion, only to find none.
A few more days of serious thought (as you know by now.. I think a lot.. and I guess this question is starting to sound like a blog rant/post of sorts...), in the interest of humanity, I thought I should come up with a generic way to address this: What if someone wanted to organize photos... organize music.. organize software?!
Turned my grey cells off for a while and here is an approach I came up with to solving my what-if scenario.
Tag / Group tag individual files (rely on a slick GUI to do it fast and do it good) - Adobe Flex/Eclipse RCP to do this?
Create hardlinks to each of the tagged files.
The first point is self-explanatory. The second (coz I am talking windows here), refers to making use of mklink.exe.
Consider a scenario where I have 2 movie files: I have a movie file "Transformers.avi" tagged as "english, action, bluray, sci-fi, imdb-top-50, must-watch-with-kids" and another movie file "The Specialist.avi" tagged as "english, bluray, thriller, adult". Here are a few of the possible locations I want to see my Transformers to be found:
[root directory]->all-tags->english
[root directory]->all-tags->bluray
[root directory]->all-tags->english->all-tags->bluray
[root directory]->all-tags->bluray->all-tags->action
[root direcotry]->all-tags->english->all-tags->action->bluray->all-tags->imdb-top-50
Given that windows has a limit of 1024 hardlinks to a single file, I probably would be allowed 7 unique tags per file. Each sub-folder will have an "all-tags" folder. Having it named "all-tags" makes it more accessible when order by name.
I believe this approach when automated to let you configure tags you want and where the hardlinks are created for you, helps you organize stuff effectively.
I don't know if there are better things out there. I would like your inputs on this approach and other possible ideas. I would like to gather inputs here and release something to sourceforge for everyone to use in a couple of weeks. I am sure, I can count on your positive response as always.
I believe hardlinks are not a good approach. Reason? A standalone player won't play them, and I wouldn't like a program who's made for tagging to tell me to stop making so many tags because of a Windows limitation on hardlinks (remembering each tag will increment the number of links exponentially).
Plus, "help" is not a good tag.
And I've had an idea once that I'm still planning to make some day to sort my own files - put the files in a big storage each below a GUID foldername (filename untouched) and store metadata in a sqlite database to be used by a smart file browser.
I was considering doing something similar to this with music for detecting duplicate songs and auto-organize funcationality.
For your application, I wouldn't recommend using any shell programs through Java. Exception handling becomes difficult, and your application becomes bound by the shell interface and implementation (i.e. windows versions or installations affect your application behavior).
I would use a database with a few tables: Files, Tags, and an association table.
The Files table would list the physical location of each file, the filename, and a unique identifier. This way, you can maintain information about each file without having to modify it for every tag association.
The Tags table would list each tag, and any metadata you want to store for each tag.
A third table, maybe 'FileTags' would store the assocation between tags and files. When adding tags to the stack, you would add a statement to the WHERE clause, and the list of files with all of the tags would be returned. This structure would also allow open your codebase up to other designs, such as include/exclude (autocomplete with X buttons), or possibly search.
If implemented in Java, your app would be platform independent, and would allow a very large number of tags and files. You can then use the system default application for opening the media file, and the user can make the selection in their native OS.
Reiser4?
...
(I mean nevermind Hans, but the tech...)
[disclaimer: Not a hacker. I know nothing of programming/coding, never mind filesystems & databases. I can barely code decent HTML even, if at all. Hey y'all! :D]
[footnote: does plain HTML5 work here? Too lazy to close my tags hehe :p]