What is the best way to externalize the static items used in iOS app? - ios

I am working on app where I have country object and I will be having around 200 instances of object. Each object will have few properties like flagName, capitalCity etc.. I started working on prototype using only 10 countries and I stored these objects inside the viewDidLoad method as an arrays. I know its not a good practice to "hard code" everything in the source code. In a real app, I would like to externalize these static items and put them in a file or database or somewhere else. What is the best way to store such information ? I am thinking of property list but if the data-model changes then I will have to re-submit the app. Any help would be greatly appreciated. Thanks

Try to load a JSON file from your web site. Create a simple JSON model, hide the file on your web site and have the app load it from there. If you want to change it, you just have to change the JSON file on your server. This way you won't have to re-submit the app.
Cache the content of the file in your app so it can work off line, if needed.
Just a suggestion.

Related

Saving data in non-document based application

I have an app similar structured to the new Notes app. A sidebar contains information about different files (date, title, excerpt) and the detail view shows the whole content.
To store data in my app, I use NSKeyedArchiver. Each file is stored seperatly to make iCloud Sync easier.
So here is my question: Is there any good way of storing and loading this data in the sidebar?
The problem is that when the app starts, it iterates through every available file to load the information needed. However, the whole object graph loads for each file even if I only need the date and the title. Is there anything I can do to optimize this?
Should I use a seperatly index file where all dates and titles are stored?
Am I using the wrong storage concept?
Any advice would be appreciated!
Sounds like what you need to do is store the key information (date and title) separately from the rest of the data.
When you start the app, you can load the key information and display it, then retrieve the rest of the data only when required, by linking the title to the content.
You could use CoreData for this - but probably overkill.
Realm will work very well for this. There's a good tutorial available here http://www.raywenderlich.com/112544/realm-tutorial-getting-started

How to create preexisting realm db?

I've googled for Realm tutorials but I only find examples of how to implement a DB in apps where the user fills the fields (like Contact Apps, To Do apps, etc); they're great, but they do not explain what I want to do.
I'm building a spanish-mayan dictionary app so I don't need that the user enter any data, I only need to display it. I've chosen Realm because it really caught my attention, but I don't seem to find a solution for what I want. Is it possible to create a Realm Object, set its values, populate its data and then display it on a UITableView?
I'm using Swift 2.1.1 and Xcode 7.2
We don't really have any official tools or utilities that can produce pre-made Realm files, but it is something we're actively working on at the moment.
At the moment, the easiest thing (And would ultimately give you the most control) would be to write a small desktop app (Maybe even a command line utility) to import your dictionary data, format it, and then save it out to a Realm file beforehand.
After that, you can simply import the Realm file (and the model classes from the utility app) into your proper app, and you can load the data from there.

App structure iOS and Realm: create database when app is installed

I am very new to iOS. I am developing an app with data persistence. I have decided to use Realm for that purpose.
I must to create the database and load data the first time that app runs. I get data from a Web Service in JSON format. I will implement some strategy to update this database later, maybe with iOS Silent Push notifications.
I have read and I have worked about Realm, loading data from JSON... to learn about that.
Now, I need to apply this in my project but I don't know how to start. I need some clues about general idea for the app:
How can I organize my app to load data when it is installed? At what point should I create the database and load data?
I have thought to create a global Realm object y AppDelegate and use it as a global variable. Is it a good idea?
Do I need to set a path for my database? Can I user default path?
If you are looking for a place to start, you can check out the example apps of this UI component add-on for Realm: ABFRealmGridController.
The controller is a subclass of UICollectionView and the example app should demonstrate most of the functionality you are curious about. The example uses the controller to display the top news stories from the New York Times. This involves making a request to their API and loading the JSON response data into Realm.
When to load the data is dependent on how you want the app to function. If the data will be the same for each user, you could bundle the Realm file with the app pre-populated with data.
The ABFRealmGridController example loads data when the user clicks the refresh button and performs the JSON handling on a background thread; a general best-practice.
Finally, unless you have multiple Realms or need to store the file in a specific path, it is probably simplest to use the default path.

Is there any way to access database of an application from another application in iOS, with objective c?

I separated some processes. I have two application and i want to access database of one of them from another. Is there any way to access?
Answer is NO.
Each and every application in iOS is sandboxed, hence one app cannot access data of another one.
(I think it can be done on jail broken device).
No you cannot access database in one app from another app.
However there are always workarounds, such as using UIPasteboard
The UIPasteboard class enables an application to share data within the
application or with another application using system-wide or
application-specific pasteboards.
First you will need to create an application-specific pasteboard by pasteboardWithName:create:
You can then save your database in one app, and convert it to NSData, then put it into your application-specific pasteboard with setData:forPasteboardType:
You can read the NSData with dataForPasteboardType: and convert it back to your database format
Hope this help.
No, you cannot directly access database from one application to another.
But, you can achieve sync process between two application, by sending data from first application to server and fetching same data from server in your second application through web services.
Hope this info helps you..
It cannot be done directly, but you can share files between applications.
You can register your application to handle particular file types (e.g. *.sqlite files).
For example you can open attachments from Mail.app in other application like GoodReader or something else.
Here is more info
No, you cannot access contents from one application to another, as they are limited to itself.

Accessing Word documents in a Rails app

I have a number of documents (mainly Word and Excel) that I'd like to make available to users of my Rails app. However, I've never tried something like this before and was wondering what the best way to do this was? Seeing as there will only be a small number of Word documents, and all will be uploaded by me, do I just store them somewhere in my Rails app (i.e. public/docs or similar) or should I set up a separate FTP and link to that? Perhaps there's an even better way of doing this?
If they're to be publically accessable, you definitely just want to stick them in public somewhere. Write a little helper to generate the URL for you based on however you want to refer to them in your app, for cleanliness (and so if you do change the URL later, for example to bucket your files to keep your directory sizes under control, you don't have to change links all over your app, just in one place.
If, on the other hand, your files are only for logged-in users, you'll need to use something like send_file to do the job, or one of the webserver-specific methods like the X-Sendfile header to check the user is authorised to view the file before sending it back to them.
I would do as you suggested and put them in public/docs. If you are planning on making an overview/index page for the files and link directly to them it would be easier if they were stored locally instead of a remote FTP server. However, since you are the one who will be uploading and maintaining these files, I think you should go with the option that's easiest for you.

Resources