In my iOS app, I need to cache hundreds of small pictures (50x50) in iPhone. I'm looking for the right way to store them. Several ideas come to my mind:
Store them with Core Data.
Store them in file system. I keep
hundreds of paths to refer them
later.
Store all of them as a big file. But
it's difficult to change or remove
one of the picture...
Don't cache them at all, read them
from web every-time I need them
instead.
Do you have any good idea?
what I'm doing is,
make on sqlite table with two columns
URL and filename.
After I get image from Web, store URL and file name in table, and store image in file.
well I've done in many apps like this. (May someone has better way)
I thinks either coredata, or sqlite3 is a good idea, i used sqlite3 to do this, but only around 200 similar images, but for more images, using coredata is definitely faster
I would use Core Data, as it would require minimal amount of work from your side, and you will be using Apple's framework, so it will probably be more reliable.
You may want to have a lookt at ZSAssetManager, it uses the file system to cache images, and does much more!
Related
I will make a simple game app which will store some data as user progresses in levels. For example: each level has a number of sub-levels, sub-level stores 3-4 properties (strings and arrays) depending on user's progress.
The app is simple and it is not a lot to store (about 150 levels and sub-levels maximum with small amount of data in each) and I do not want to make it complicated with multiple classes representing levels and sub-levels plus SQLLite database. I thought of a simpler approach but good enough to manage data through my GameManager singleton.
Recommend what approaches to look at for my needs to store and manage data for this type of an app. Perhaps one of these or something else:
NSUserDefaults + NSDictionary
CoreData + SQLLite
etc...
Just want to make sure I am not missing anything
It's much better and less painful for you to use core data. Why do you say sqlite?? Core Data is just saving your objects in a sqlite file on an iOs device and in xml in Cocoa app.
To use plist files is kind of strange, as I think. You can put into it only a simple array, and what if you want to display photos besides your simple array? The preferred way is core data - 50% less code, as apple says. Use NSFetchedResultsController and you'll be good!
Another widely used practice would be to store your information in a property list (.plist). NSDictionary and NSArray come equipped with the capability to load from as well as write to a property list.
Here's a resource which may be helpful to you: Property List Programming Guide
Take a look into core data. It seems very difficult once you get started. But once you get into it, it gets pretty straightforward from there. Check out this tutorial he helped me get going. Hth
i'd like to make some application that store data in device.
so i want to use some storage. but there are two ways i can store my data.
first one is saving them to file system by XML structure, and the other one is by using sqlLite library. but i have no idea. because i don't know the strength and weakness each of them. for example location of stored data, and which one is faster to get the data i want. i just store text data. so please recommand which one is better.
sorry for my english skill. thank you!
SQLite !!! No doubt about that.
For easy maintenance, querying capability and lot more.
SQLite has the basic features of a database engine, it's lightweight. Specially designed for mobile platform. So some features like regex in database etc is not included.
File and Database. Always preference goes to database.
DATABASE ALWAYS...
As you said SQLite is one option, and you can use SQLite directly with iOS. But I hope you have heard about Core data, which is a higher level wrapper to make Database easier.
But there is no comparison between Database and files
This would be Perfect answer for your question and for iOS I would suggest SQLite will be the best one as it has everything in one file,
performance loss is lower than XML as cache gets bigger.
It depends on the amount of data (and its structure and complexity) that you are going to store. For rather small amounts, not more than a handfull of records or two, I would use an NSDictionary and the load and save methods that come with it. Those persistant storage will be in XML, btw.
For more data or rather complex data, especially when you do not need to load all the data at the same time, then you should go for a database solution. That chould be sqlite. Or you may opt for core data which (per default) is based on sqlite.
I would suggest core data (unless you aim for portability such as android). You will have to invest in learning core data. Which may appear to be confusing from start. But once you have started with that you will certainly find core data quite convenient. It takes a lot of work from you that you have to care for manually when using native sqlite.
I'm making a game and I need to be able to ship some data about the game's various ships and details about them that the app will use. I'm looking for what the ideal way to do this would be. Now I've narrowed it down to using either SQLite, Core Data, or Property Lists. Now the thing I want to keep in mind as well is memory. Because it's a game I need to be careful about this and because of the fact Property Lists need to be loaded all into memory I'm afraid they might not be ideal. I know SQLite is supposed to have better performance than that and I've heard that Core Data performs even better than that. So my question is what do you think the best way to ship static data with an iPhone app is?
I would say it depends on the amount of data that you need to provide. If it is a lot of a data, I would definitely go for sqlite. If it is just a couple of ships, sqlite might be a little over the top.
For a such a small amount of data why dont you consider writing your own file format, or using something easy to parse such as csv, will be easy to edit in any spreadsheet program, and to cut down filesize / load times convert it into a binary format.
Assuming that not all ship-data is needed at the same time (and as such, having them all in one file would be a waste): Maybe you should use a separate data file for each ship or each class of ships?
Since this would solve the storage-efficiency at a different level, plists might be a viable option.
I have an application where the user will navigate around a set of photographs. What's best in terms of performance for this scenario, SQLite + Core DATA for persisting the photos as NSData objects or having the photos as png files directly on the file system?
thanks.
It really depends on the size of images. I would certainly put small things (like thumbnails) right in the DB. If your images are large you will either want to put them into separate files, or be very careful that those columns are not faulted in unless you actually need them.
With CoreData you can just use a computed property to load and save the external file.
I'd agree with Louis. The file system is almost certainly going to be faster for images of any significant size.
Is there any "Best Practice" approach to storing persistent static data for iPhone apps?
I have an app that reads a dictionary of approximately 1000 items many of which are arrays. I started out using a single plist for this and it has become somewhat unwieldy especially since much of the values are HTML strings.
Is there a better way for me to approach this? I plan on scaling this app significantly and I obviously don't want to change my approach midstream.
I've googled for iphone data storage and variants but have come up short for anything even touching on a best practice.
It sounds like you intend to distribute some data with your application. A property list is probably the easiest to maintain, but it will be loaded into memory all at once. This could eat up a lot of the device's memory.
An sqlite database, on the other hand, will load only the data you request. I'm not sure how your data is structured, but you could quite easily create key-value pairs with a single database table. (A single table with a key column and a value column) Then, if it were me, I'd write an Objective-C class to wrap the database queries so I can write easy statements like:
NSString *welcomeText = [[MyData sharedData] dataWithKey:#"WelcomeText"];
Getting the data into the database in the first place doesn't have to be difficult. You can use the command line sqlite3 utility to bulk load your data. There's a command called .import that will import your data from a text file.
Hope this gets you moving in the right direction!
I'd go with a sqlite solution. The apps I am working on now, which are just apps to help me learn iPhone development, mostly all use sqlite. I use the sqlite plugin for firefox to help with maintaining the database, which works surprisingly well. https://addons.mozilla.org/en-US/firefox/addon/5817
As Alex suggested using a wrapper class would also be the best way to go.
Don't forget with 3.0 you can use a CoreData layer around SQLlite which may make it more appealing to you.
If you don't need to store any relational information about your data, why not just use files? There will be some wasted filesystem space, but plain files might be the most memory and CPU efficient solution, depending on the size and number of your items.
I've never developed an iPhone app but I have played around in the filesystem. I have seen sqlite databases floating around various places of the phone. I'm pretty sure it uses a sqlite database to store your calendar entries.
I would use sqlite. It is already there, easy to use, and will provide the most flexible path for expansion in the future.
I use sqlite for static data in my iPhone apps all the time.
All I did was save state when the app is shut down. I used a file for that.
sqlite sounds perfect for your app. sqlite is pretty easy. I've used it in Adobe AIR apps.