How to preload data into a database for iOS? - ios

I'm creating an app that manages mileage. There are pre-set miles for each route (there are 28 locations with routes between each, the mileage is set for each).
I am trying to 'preload' a database table with those routes/mileages so that when the user tracks a new route they've gone (say point A to point B) the app can easily figure out how many miles the user traveled with a quick query.
I've done website development and am familiar with mySQL - but there are some GUI's that I use to preload that data (phpmyadmin); there doesn't seem to be anything similar with the iOS that I can find so I can preload the mileage data into a table (entity?) so I can work on creating the interface to work with that data.
How should I go about achieving this? I am hoping to use core data to achieve this if possible - although SQLite seems like another options some have mentioned. But even others mentioned just holding that data in an array. Being so new to iOS programming - I'm just looking for a solid way to accomplish a pre-loaded database table.

Per the comment from Aaron Brager - using this tutorial I have went with Core Data
http://www.raywenderlich.com/12170/core-data-tutorial-how-to-preloadimport-existing-data-updated

Related

Difference between core data & NSUserDefaults-notes app

Creating a budget app (not for release, just something quick & dirty) and I noticed upon starting the Master-Detail template that Apple uses Core Data and NSFetch results to populate the tables (think Notes on an iPad).
My inexperienced and unprofessional programming instincts wouldn't think twice about grabbing an NSMutableArray, taking the names of the table cells and cramming them into an index, saving that as an NSUserDefault and then upon reloading the app, populate each cell at it's current index with the same index in the NSMutableArray so the contents is back where the user left it. Just wondering, how inefficient is this compared to using Core Data?
On a side note, any easy way of communicating between two different tables that both hold dynamic data?
Up to a few hundred records, don't worry about it. It would be indeed wonderfully "quick and dirty".
Still, the learning curve for Core Data is not as steep as you might expect. Once you get the hang of it - and your simple app is great way to explore that API - you will find that you want to do everything with it. Even large projects will seem easy.
Your choice.

Creating simple database for iOS application

I'm planing to create an app for iOS which will be kind of informative application for public transport in my city. People will enter street name from where they want to get public transport and will get list of buses and minivans, which are traveling by that street.
My problem is that I'm just started developing for iOS and want to find easy method to create a database/table with simple information as streets name and bus numbers that will connected with those streets.
So basically I need to create database/table and an search-box which will be connected to that database.
From where I need to start? Thanks.
p.s. - sorry for my bad english ;)
SQLite is quite popular and supplied by Apple. This lets you manage your table, and allows most standard SQL queries. You can also link to Core Data if you want to treat your data as objects.
See the Apple overview
There are many tutorials to build a simple app with a table view using SQLite, e.g. here or here
I found the Stanford University videos a good way to learn this stuff, e.g. here on YouTube or there are later versions available in iTunes U.
Yep, for an on-phone database SQLite is the way to go for a full-featured database, or Core Data if you want some "hand holding". And, of course, if you don't need persistence you can make a pretty good database simply using NSMutableDictionary and maybe a few custom classes.
Learn to use CoreData. Its not there to "hand hold" you, its there to provide a complex and optimized ORM interface for the underlying SQLite database-- there are a number of optimizations implemented to improve efficiency. You could pick it up in a night following tutorials and online instructions.

iOS Map Kit Locations read from database

I have been tasked with creating an iPhone application for a client.
I have some coding experience but only in C# so it doesn't really help here but other than that I am a complete novice on iPhone coding.
What I am trying to accomplish is to get some form of store locator on a map.
I have successfully added the map, get the user location with it zooming into the user. I have added 2 annotations (Which I believe the the best way to go about showing locations on the map).
I have 2 queries that I need help with, What is the best way to go about listing the stores in some form of database. XML, PList, .sql etc... (this would also need to be read from the web as it would need to be easily edited as new stores would be added a lot). Is it possible to loop through the database and dynamically add the stores onto the map within a location of the user?
I am not asking anyone to write any code for me, I am just asking for some help as I have googled the hell out of this and cant seem to find anything that helps.
Any help would be much appreciated,
Thanks
In terms of your potential formats for saving these locations, you options include:
XML/JSON are good formats for exchanging data with a remote server, but less ideal for a local database (though they theoretically could be used for that purpose). JSON is marginally easier to deal with (using NSJSONSerialization), but XML can be relatively easily parsed, too (using, for example, NSXMLParser). If you're doing network operations, I also heartily recommend looking at AFNetworking, which offers some nice advantages over the standard NSURLConnection. This, of course, presumes that you have written a web service on your server to deliver the necessary JSON or XML feed.
Plist is a fine, simple format if you want to save a short, local list of locations on iOS devices. Saving data to a plist is as simple as calling writeToFile method for your NSDictionary or NSArray and reading data is done via [NSDictionary dictionaryWithContentsOfFile:filename] or [NSArray arrayWithContentsOfFile:filename].
Core Data is a good, iOS-specific format for larger databases. It's probably the preferred iOS mechanism for dealing with persistent objects, but is an order of magnitude more complicated than plists.
SQLite is also a good database format if you're thinking about a structure that lends itself towards larger database, but also which lends itself towards eventual rollout to multiple platforms (e.g. both Android and iOS). If you decide to go SQLite route, consider an Objective-C wrapper (such as FMDB), which will simplify your life greatly.
Implicit in all of the above discussion is that, yes, you certainly can write code that iterates through your database and/or model data structures, extracting the necessary location information, and dynamically add annotations to your map. The Location Awareness Programming Guide should help introduce you to some of the MapKit related features.
"Is it possible to loop through the database and dynamically add the stores onto the map within a location of the user?"
Yes. Just as you have created those first two annotations, you now need to create more annotations in a loop. The only additional info you might need is that once you have added an annotation to the map it will stay there until you remove it. So you don't need to maintain your own list of annotations unless you want to do something else with it. Just fire and forget. So now your question comes down to how to loop through data from your chosen data source in Objective-C and not MapKit specific.
I know this is old but if anyone else comes across this like I did, you can use tmysqlkit by tanmay bakshi to read and write directly to a mysql database on a server.
Best,
Sam

Design pattern for Core Data default entries

I'm planning a new ios app and am not sure of what is the best way to set up a start list for a tableView on first app start. The app uses Core Data (more precisely Magical Record). Should I use some kind of (p)list (dictionary) which gets imported or should I just hard code the default entries like when the user adds something through a formula? Thank you!
There are a load of arguments for and against all different ways of doing this.
Personally I prefer just to hard code all the default entries (if there aren't thousands of them obviously).

SQLite or CoreData [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Use CoreData or SQLite on iPhone?
I would like to build an App which enables you too find stores (for example stores with your favourite shoe brand) even when you're not connected with WiFi or 3G.
For now the App should have a couple of possibilities:
User selects his favourite brand and gets a list of nearby stores. After that the user must be able to select a store to get the address, contact information and maybe a map;
User selects a certain city, gets a list of the available brands, selects one and gets a list of stores in that city selling the selected brand.
Since I'm new to making this kind of Apps, I have started doing my homework. I know I have to use a database to store all the data and found out there are a lot of ways to do so. One of them, creating a MySQL Database, wouldn't be an option since it can't be used offline. If I'm right two other methods are SQLite or CoreData.
Problem is, I'm getting kinda lost in all the available information which makes it hard for me to start. Are both methods possible for this App and which one is the easiest for this job?
I was hoping someone could point me in the right direction and maybe give me an usefull link or tutorial to continue with my App.
Thanks in advance! :)
Only use SQLite if you already know it, or you know that your use case is one of the rare few that has proven difficult for Core Data.
Thus, I would think your decision is simple. Use Core Data. It's extremely simple, unless you start updating data from multiple threads/contexts at the same time, then it gets pretty hairy relatively quickly.
There are tons of tutorials available online for Core Data, and ou always have Apple's documentation and sample code on their developer web site.
If you've never used MySQL or SQLite, just use CoreData. But if you have used MySQL or SQLite, i would recommend using SQLite as it will be easy for you to understand and thus you will be able to develop your app faster.

Resources