iOS Map Kit Locations read from database - ios

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

Related

iOS Application: Portable Data Storage of many Key/Values

What is a good way to store many key/value pair entries in a mobile (iOS) application, such that they can be easily exported/imported?
I have considered a single large JSON file - would this be too slow/large with 200,000+ entries?
I have also considered CoreData - but could the data be moved easily via, for example, email?
Think of an address book. Contacts can be easily imported/exported, what data storage model would be comparable?
Thank you.
EDIT: Examples
Notes - be able to select and view short notes in a table. Each note is < 100 characters.
Saved bookmarks - each bookmark is stored in a table.
I have considered a single large JSON file - would this be too
slow/large with 200,000+ entries?
I don't know. I can make a guess. The guess would be yes, it's both too large and too slow. However, you can always test it to find out.
I have also considered CoreData - but could the data be moved easily
via, for example, email?
That depends on how you want to share the data. You call email easy?
Core Data is a framework. You can use any type of backend you want (you can even write your own). The most common is probably SQLite.
If you use Core Data, you can keep the data files in a separate subdirectory and copy them just like any other file.
However, if you want to share data via an online service, you may want the ability to import/export JSON files.
If you are talking about synchronization, then that's a different beast entirely.
Basically, there is no single right answer. You have to assess your requirements, and then determine which solution meets your needs.
On the surface, it seems like using Core Data would be a good fit, but it depends on how you want to use the data in your application. Only you know that answer.

Apple ResearchKit: how to extract information from ORKResult? First time programmer

I'm working on a simple ResearchKit app that has 20 survey questions, or ORKSteps. How do I get the answers from a participant who submits the survey into a database?
My research has found ORKESerializer and SQLite as potential parts of the solution. I'm missing a big picture view of how these things can be integrated into a working solution.
Starting without knowledge of databases or data transfer from Swift, so any basic information would be very helpful.
How do I extract data from ORKResult using Swift?
Where do I extract the data to? Or, what's the standard type of database for a small survey?
ResearchKit doesn't have any out-of-the-box solution for storing your results. Generally, it's the task of the developer to go through the ORKResult hierarchy and either persist the processed results for later access or send them to a remote server.
You have several options here:
Use NSCoding to store the vanilla ORKTaskResult (with their ORKResult children). This way you can recreate the whole ORKTaskResult hierarchy at later time to inspect or process it.
Use ORKESerializer (as you guessed) to serialize ORKResults into the JSON format. ORKESerializer is currently included as part of ORKTest's unit tests, and it's not documented very well. It's possible that it will be moved to ResearchKit proper in the future, but it's completely usable right now. The JSON format is particularly useful if you want to send your results to any remote server of your own.
You can manually iterate through ORKResults and convert them into objects that are suitable for storing, or into database records. As you said, you could persist them using SQLite; or other database of your choice; or Core Data.
To sum up, there's no recommended or standard method for persisting results, it depends on your needs.
You can also have a look at the official open sourced RK apps. I think they make use of the AppCore library (which sits on top of the ResearchKit) to store the task results (and also use the Sage Bridge to send the results to Sage's servers). But that may be overboard if your needs are simpler.
I suggest that you run the sample ORKCatalog app and then inspect the ORKTaskResult hierarchy (you can do that within the app itself). You'll get an idea of how the result hierarchy looks.
I do not have experience with the Research Kit but as a database you could use sqlite. stephencelis has made a great wrapper for swift which you can use.

iPhone local storage -- Core Data, NSFileManager, ...?

I am making a simple iPhone app that will basically be an editor.
As such, I need some way to store the documents the user creates.
Since on iPhone, the concept of the filesystem is not present for the user, I searched around to see what I should use.
I found this question & answer that basically says to use Core Data, but I recently found out about NSFileManager.
My question simply is, for user-created documents, what is the best storage system to use? Traditional files by using NSFileManager? Core Data? Something else?
Personally, I would use CoreData because it will abstract away all of the file-management code for you. If you are making simple text documents then this isn't such a big deal, but if you are working with a complex document architecture (i.e., a collection a numerous objects) then it can save you a lot of effort.
If the user wants to export their document it is very easy to write a function to do so with your CoreData objects.
The only downside to CoreData is that if you are using non-standard attributes it can get a little bit tricky, but it is certainly not a deal breaker in most cases.
People create document formats without CoreData all of the time, so there are plenty of examples out there, and it will just come down to personal preference. There really isn't any generalized right answer to this - it a design decision that should be evaluated on a per-app basis.
If all of your data for displaying the file is contained in one long string (like HTML) then I would recommend that you use the file manager, since it will be easy to get a list of files in a certain directory to display to the user for opening. However, if they are not self contained (like NSAttributedString, which has many stored formatting regions along with the actual content) then you should use CoreData, as it will be easier to keep all the pieces together.

Initialize Core Data With Default Data

I have a basic question regarding populating Core Data with data. I am building an application, which will show ATMs on a map. I would like to ship the application with a preloaded database, but to give users the option to receive updates when they launch the app. I am thinking about using a property list for the update. Basically send a plist of all the ATMs, parse that plist and populate the sqlite. I will have around 7000 entries in the property list file, each entry containing 5-6 keys with short string values. But according to the Apple iOS Developer Library:
You can create a property list—or some other file-based
representation—of the data, and store it as an application resource.
When you want to use it, you must open the file and parse the
representation to create managed objects. You should not use this
technique on iOS, and only if absolutely necessary on Mac OS X.
Parsing a file to create a store incurs unnecessary overhead. It is
much better to create a Core Data store yourself offline and use it
directly in your application.
Should I still be sending a property list or rather think for an alternative solution to update the application's database?
P.S. I am thinking about using a Rails app for providing updates - basically sending a plist file.
I had nearly the same question a few months back, did quite a bit of searching to find a nice easy answer, failed to find it and eventually settled on a roll-your-own solution that took a bit more time than I would have hoped, but was at least very helpful in learning to understand Core Data.
Basically the solution was to write a little utility that parsed my source data (which for me is a comma-separated text file, parsed using the quite handy 'cCSVParse' library - http://michael.stapelberg.de/cCSVParse ) and inserted it into Core Data Managed Objects and then saved that off as a sqlite persistent store. Then the sqlite store(s) can be shipped with the app, and uploaded by the user when they buy more data.
You could write a conversion from plist (or whatever) into the core data representation within the app itself, but if the data is just going live out the rest of its days in some core data form, why not let your beefy dev box do the heavy lifting before you send the data to the user, instead of shipping the data to the phone and making it do the work?

plists vs Core Data for holding parameters

I am writing an iPad app that will be expandable with new items via in-app purchasing. For example, my current plan is to have a jpg pattern and a matching plist file with the parameters I need to expand that pattern into a full picture.
The user will select one jpg/png from a list of small thumbnails - the list is held in Core Data - and the app will find the matching plist for displaying the jpg/png correctly. I'll only have about 10 of these open at one time. But I could end up with storing 1000s of jpgs and plists.
Does storage of lots of small files cause app problems?
I'm going the plist way, rather than storing the parameters in Core Data, so that if I need to add parameters later, I don't have to migrate the database, just change the access in code. (And when I'm creating the patterns, it's easier to concentrate on a plist file rather than a Core Data row.)
The app seems to work really well at the moment, but I'm worried about futures...
My app does also use Core Data for other things, so I could change over if the app will get bogged down with number of files.
Thanks.
Saving a large number of small files is not a problem as long as you have a well thought out means of naming and tracking the files.
Remember that the user does not have the same flexibility and ease of file management on a mobile as they do on non-mobile platforms. Designs that work on non-mobiles are unworkable on a device used on the move with one finger.
However, when you say:
And when I'm creating the patterns,
it's easier to concentrate on a plist
file rather than a Core Data row.
... the use of "row" suggest that you haven't fully grasped Core Data's utility. Core Data doesn't use rows, columns, tables or joins. It's an object graph management system that sometimes uses SQL way behind the scenes.
Core Data is designed to handle data in a way that meshes seamlessly with the rest of the object oriented API for the UI and other services. When you use other data management systems like plist, you will most likely end up manually duplicating a lot of Core Data's functionality anyway.

Resources