Large-ish data storage for UITableView (Xcode 4) - ios

Alrighty,
I am new to Xcode so I apologise if I am missing any key points here.
But, I want to have a large list in a UITableView type display. The list will be an array of strings with maybe 500 ish entries and a search bar to search for what ever entry you like. Once found you can tap the entry and it will load a detailed view of what ever it is. I would prefer to not have to have all of the data entry in Xcode and am wondering what would be the neatest way to store/read/write this?
I am leaning towards some sort of data file... but couldnt quite work out how to implement this into Xcode. I have searched around a bit but couldnt find anything which made sense (probably because i am quite new to Xcode).
This will be an App for iOS.
Any ideas?

I understand that you want to create a UITableView displaying static data and your problem is that you don't want to store the data in your code. Depending on how complicated the structure of your data is you could save it in a sql database, store it with coredata, keep it in a xml file or keep it in a file in a custom encoding. I don't quite now where your Problem lies. You can just load the file/database, parse it in an object structure and display it in the tableview. There are a couple of advantages of using a database to a file:
You can create connections easily and handle them without a lot of effort
You only need to load in the memory what is really needed at the moment.

Core data will be fine for you. However if you don't need all of its extra functions and the list will be static (eg, non changing and will be read into the code at runtime in its entirerty) then you can probably use a plist. Plist data can be read directly into arrays.

Related

Simple read-only data storage in iOS (with easy editing and visualization)

I've used archiving, user defaults, and some Core Data in my apps before, but I'm running into a wall re: the best method for my current scenario. I have an app that needs to instantiate some objects from a resource file each time before it's used. An example of one of the objects could be a "MathQuestion" object that has the properties:
questionID (Int) - 2341
questionText (String) — "What is the square root of _?"
questionVariable (Float) – "4"
correctAnswer (a block/closure that returns a Float) – "{return sqrt(value)}".
Ideally, I'd just have something like a spreadsheet with columns for each of these properties and rows for each of the different questions. That way, I would really be able to visualize all the data and make quick changes during development.
My app uses Parse, which is great for visualization and easy editing of values, but for this case, I'd rather the resources remained on the device and not the Parse server. I've been considering Core Data up till this point, but (this could be my inexperience with C.D.), I'm unaware of any way to manually edit the data—and it seems like it may be overkill for what I'm looking for anyways. (I basically just need a way to upload and parse a CSV!) Any advice would be welcome!
I would still recommend Core Data. It is simply the most efficient and scalable mechanism to store and retrieve data.
When I work in your kind of scenario, what I often do is work with a spreadsheet where I can conveniently edit the data. You could edit a CSV version of it that you have included in your target. (If this does not work for you, you could also copy paste into a separate CSV file right into Xcode.)
On every start, you just trash the data store (using NSFileManager when creating the NSPersistentStoreCoordinator). Then you call a method that reads in the CSV and stores it in Core Data.
Once you are done with development, you simply keep the sqlite file (you can include it in the bundle and copy it over, or re-generate it from your CSV the first time the app runs).

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).

iOS app - separation of code and content with various elements

I am new to iOS app development. I have been reading the documentation on the Apple Developer website as well as reading references on the Internet and I still can't seem to find anything that explains how to separate content from the app such that the content itself is easy to update. The open source iOS examples I have seen all hardcode content into implementation files. Although I have read up on Core Data, I'm not sure if that is the most approriate framework to use for my use case. I want to make a basic app that simply contains lots of views with each view containing various types of UI elements as those seen in HTML for example H1, H2, H3, P, UL and IMG. With Core Data, I'm assuming I would have to somehow save my data(content) into a SQLite database file and then get the app to read it, would this not be tedious? How would I then update the SQLite database in addition to populating it in the first place?
To reiterate I simply want to know, what's the best way to achieve this and still be able to update content relatively easy without having to go to a file that has the content hardcoded.
Many Thanks
easier way is to fit them inside plist files, then read them as NSDictionaries
please read Plist Array to NSDictionary
and Parse Plist (NSString) into NSDictionary for more information

How to simply store some files

I'm developing an app which needs to show some logos. These logos are just 8kb PNG files, and I'm just going to handle a little amount of them (10-20 at most). However, these are downloaded from the Internet because they might change. So, what I'm trying to achieve is, making the app to download them (done), storing them into the file system, and only downloading again whenever they change (might be months).
Everyone seems to use Core Data, which in my opinion is something designed for bigger and more complex things, because my files will always have the same name plus don't have relations between them.
Is the file system the way to go? Any good tutorial?
Yes, the file system is probably your best option for this. You say that you've already implemented the downloading. How have you done so? With NSURLConnection? If so, then at some point, you have an NSData object. This has a couple of write... methods you can use to save the data to a file on the filesystem. Be sure to save the files in the right place, as your app is sandboxed and you can't write anywhere you like.
The advantage Core Data brings is efficiency. Using NSFetchedResultsController to display your logos in a tableview gets you optimized object loading and memory management. It will automatically load only the items which can be displayed on one screen, and as the user flicks through the table it will handle releasing items which move offscreen. Implementing that on your own is not a simple task.
If you want to build and display your data without Core Data, you'll probably want to use NSKeyValueCoder, which will allow you to easily write an array or dictionary of objects (including nested arrays, dictionaries, and images).

Resources