So I am working on an iOS search where I have to implement a keyword search. I have used a custom view controller with a Search Display Controller object embedded into it. What I want to do is be able to store the search terms somewhere when the search button is clicked. I have thought of two ways:
store them locally in the device and query them up whenever a search is performed
store them in the web app this iOS app is connected to and perform a GET request to the web app whenever a search is performed
The second one I know how to do but I have no idea how to do the first one.
SO how do I store the search terms locally? Also, what would be a better option? The first, the second, or another?
EDIT: A remote API holds the data I am querying. I want to mimic the google search app functionality, in which it stores maybe 10-20 keywords that are searched by the user.
Thanks in advance!
It's tough to recommend with more understanding of the data and usage. For example, number of keywords? keyword list static or grows? keywords shared? what are you searching - local or remote?
EDIT: You clarified 10 - 20 strings. In that case, consider something as simple as -[NSArray writeToFile:atomically:] and just persist in a file. If you read and write in NSArray, you can work on them very quickly in memory.
Original:
If you store locally and it's a growing dynamic set of keywords, I would recommend CoreData or Sqlite directly. Sqlite is a very fast efficient local DB. If you do sqlite, checkout fmdb on github. It's an objective-c wrapper.
Concerning the pros and cons:
Local storage will be faster - you won't have network latency. Especially if you want to do type ahead queries on key stroke. Keeping in memory is even faster.
Consider how much data you're storing. How many key words are there? Is it feasible to store on the device in a DB or a file?
Do you want the keywords to be shared from multiple users? In that case either storing on the server or a combination of storing on the server and syncing to the device is needed.
Do the keywords grow over time based on usage? In that case a local database is better.
Related
I am creating a Questions and answers app for iphone which allows user to answer the questions displayed.
Currently I am invoking a web service to store the users answers. But I am slightly worried what if the web service goes down. I need to store the users answers locally and then invoke the web service when it is up and running.
How can I store the users answers when the web service is down. Is Sqllite a good option for this?
Please suggest.
Thanks,
Is Sqllite a good option for this?
Yes, SQLite is decidedly a good option. The other choice would be Core Data.
Use CoreData or SQLite on iPhone?
It depends on the complexity of your data model. I've looked into something like this recently and here is what I learnt. The most popular data storage methods in the iPhone are:
plist
Good for small quantities (hundreds of Ks) of hierarchical data.
Bad if relationships or queries are complex (since you have to write the code).
Very easy to learn.
Supports array, dict, string, data, date, integer, real, boolean elements.
You can store it as XML, which is editable and portable, or as binary files, which is faster.
Core Data
It's a object graph manager with searching and persistent functionality.
You need a good few hours of learning.
Easy to use once you set it up.
Better than a plist because it lets you manage object graphs, grow your object model, write queries, undo/redo, migrations to modified data models, memory management, and handle concurrent access.
Better than SQLite because:
The performance is similar and the speed of development is faster.
Creating objects is faster.
When the objects are in memory, executing queries doesn't require a search in the backend (which usually is either memory or SQLite).
SQLite
A database.
Better than Core Data when the operation doesn't require you to bring objects to memory. Example: update, delete, and select 1 (see if something exists).
It has full text search if you compile the extension.
Hardest to learn. Easier if you use a wrapper: FMDB, egodatabase.
If you can get away with a plist do that. If you see the amount of code you will have to write is too much work, then switch to Core Data. Only if you are an expert and absolutely need the performance use SQLite (unless, of course, you already know SQLite and not Core Data).
It should be, yes. I'd set up a Core Data based app with entities for Questions and Answers and set up relationships between them. Then just use NSFetchedResultsController or whatever you would like to gather and display the data
You have several options:
Sqlite
Core Data
Client-Side storage
If you wish to go the web based route, I'd take a quick look at Safari Client-Side Storage and Offline Applications Programming Guide.
Basically, you store a local copy of the database in memory so incase the web service is down, users can still use the app.
So I have been doing lots of reading and found out NSCache is not persistent which is a slight problem for what I need to do. I have heard that I will need to use Core data instead... but I don't have any experience with core data so am wondering if its the only solution for persistent data.
The app will allow the user to search through a catalog, by typing in a search parameter in the code and select a distributor for their search parameter. What I want to do when the app loads is download the list of distributors and save them to a "cache" the will be persistent (till when the header I will make at some point changes and demands the app to update the cache), so that if the user turns the app of or the phone next time then open it the manufacture.
Now that I'm getting abit deeper into my app I'm getting abit lost in things for instance how would setting up a cache work with regards to NSURLConnection.
Any suggestions or code examples would be greatly appreciated..
This previous answer of mine might help you decide.
To sum it up:
If your data is small, static and low-complexity, use a collection class and write it to disk using the built-in class methods
If the data is static, low-complexity but large, SQL may be a good solution especially if you already know it.
If the data is dynamic and complex regardless of size, then Core Data is your best choice.
Viewed purely from the technical perspective, Core Data is always the best choice for iOS/MacOS API apps. Core Data is not just a persistence API, it is an API for creating the model layer of the Model-View-Controller design paradigm that the Apple API uses. It not only persist the data, but models it, validates its and provides an easy interface to the rest of the API.
If your going to be writing iOS apps, you need to eventually learn Core Data. However, it does have a learning curve and you should pick the method right now that will let you ship a usable app.
You can also check out sqlite. Here's another question that discusses getting started with sqlite on the phone: Where's the best SQLite 3 tutorial for iPhone-SDK?
The advantage to sqlite is that it is fairly easy to pick up. The downside is that you have to write queries for everything, and that can be a pain. It doesn't save objects, just data, numbers or text.
im currently porting my iphone app to android. this app makes heavy use of sqlite data. on the iphone i populate my custom objects with sqlite data, open and close my connection to the database multiple times on demand
however on the android, i have not come across many tutorials which follow this approach. they simply use a cursor and show the data directly without making use of custom objects and collections
i wanted to know if there was any particular reason for this on the android? what would you suggest me to here? ie: is it feasible to have an always on connection / cursor the the sqlite db on the android and display the data directly OR go the iphone way that is to populate collection of custom objects from sqlite and have the UI data bound to this collection instead of the sqlite cursor
thanks in advance folks
I don't think optimal approach will vary with platform to any significant degree.
Sqlite keeps caches in the connection, so it's usually advantageous to keep the connection open.
You can save some time by preparing the statements once and reusing them.
Query startup is quite significant, so join everything you will need in one query. Getting a list of objects in one query and than starting separate queries for individual objects is very slow compared to join statement.
If you can populate the UI objects directly from the database, going through any intermediate objects is just putting unnecessary load on the memory manager (whether ga
I'm working on an application that has a read-only database shipped with it.
The user will run the application and be able to select a series of "favourites" from the database which will appear in there "favourites" tab bar section. I.e. storing the primary keys.
With each update to the application the read only data will potentially contain more entries or have things like spelling mistakes fixed etc.
I'm using Core Data but I'm unsure whether to use it for storing the users "favourites" as-well. As - to my way of thinking - this might cause headaches for migration. Is this the case?
Should I consider storing the "favourites" in a plist perhaps and perform some sort of query to retrieve the records? Any recommendations?
Also what internal pieces of an iphone application are kept (or can be kept) during an update?
Phew I think that's it.
Thanks for any answers you might have.
Cheers,
Matt
I'm using Core Data but I'm unsure
whether to use it for storing the
users "favourites" as-well. As - to my
way of thinking - this might cause
headaches for migration. Is this the
case?
If you're going to port the app to another platform, then Core Data is not the way to go. And since we are talking about a static database, I'd keep it simple - read it once, do what you need with it and close it and forget about it. Not like a real database where you're doing multiple GETs and some amount of additions, modifications and deletions.
Should I consider storing the
"favourites" in a plist perhaps and
perform some sort of query to retrieve
the records? Any recommendations?
Your database could be a plist too. After the user selects their favourites, you can easily store them in yet another plist. This one goes in the Documents or Prefs folder.
When you release a new app, you should probably compare the favourites with the new entries to correct any typos or other changes, if applicable.
Also what internal pieces of an iphone
application are kept (or can be kept)
during an update?
I believe that your app is replaced but your Documents and Preferences folders are kept intact.
Hey guys, I want to store a categorized list of URLs. This is an internet radio streaming app, and so I want to have at least three links for each genre:
the free streaming URL with commercials
the premium streaming URL at 128 kbps
the premium streaming URL at 256 kbps
So every genre will have these three URLs.
For the premium streams, there are also 'geo-localized' streaming URLs, or 'mirrors', for specific global areas. For example if I am in the United States, I can choose a closest location of the available mirrors for potentially better streaming quality/reliability.
These URLs can, though I doubt often, change, and so I will want to be able to update them, meaning the storage can't be read only. I don't know exactly how I should store the information, let alone in what type of storage: sqlite db, XML, or property lists. I'm new to all of this so I'm sorry if any of those is stupid for this situation, heh.
As for the structure, I'm not sure how to accomplish that either. I can possibly have separate files/databases, whatever I end up using, for each location, or I could have one big one that is something like:
Rock
Los Angeles
Free stream
Premium Stream - 128kbps
Premium Stream - 256kbps
But I figure the database/file would quickly become huge.
I guess I can also have separate files/databases for the free and premium streams, given that premium users most likely will only want to listen to premium streams (But still have the option of the 128kbps or 256kbps stream, depending on their network reliability). I could then have an option in the settings as to which streams to show; free or premium. This should cut down on the size.
I later want to present these URLs in a table view and navigation controller. The root view will be the list of the genres, and by drilling down into each genre it will show the free or premium streams. The location (such as Los Angeles) will be chosen in the settings, and will not appear in the table view.
I would appreciate your guys' suggestions. I tried to be as clear and specific as I could, sorry if I missed anything. I'm not asking for code, just what your ideas and suggestions are on how to design this persistent data store, and in what to store it, given that I'm new to this.
Thanks!
If I understand you, you want:
A list of genres, each containing a list of locations, each containing a list of qualities, each containing either a set of data (including URL) or just a URL. Either way, you can do this as a property list, and its just getting the the borderline of where you want to be with a property list as opposed to a database.
SQLite is on the iPhone, accessed by the standard C function API, although Core Data is not. SQLite would certainly allow you a lot more structure to your database and your queries.
Either way, you could include some sort of seed ID for the database, and then query an online server to receive just differences and that would reduce the need for transfering a large database over the net - but you'll need to determine just how large your database is before deciding on whether that is worthwhile. Simply compressing the XML file might be all that is needed, since the XML would compress a large amount (probably to ~ 30% of its original size).
Alternatively, you probably only really ned the area-appropriate sections of your database.
Something else to consider is that for compatibility with pre OS 3.0 devices, Core Data (SQLite) isn't really an option.
Besides Core Data's (un)availability, I'm not sure that the data you need to store maps cleanly onto a relational data model. I'd lean towards the plist storage. I think it makes the most sense given your needs.