Provide example for why it is not advisable to store images in CoreData?
this question has been asked many times, I have read many users telling that it is not advisable to store images in a DB, in particular within CoreData. By they all seems to omit the reason why they would do so. Even Apple documentation state this, and everybody points to that direction, and every discussion end like this “well you can, but storing the path is better”.
Apart from opinions, I would like to have a concrete example of why it is not a good solution.
I explain better, I have a strong background in building Web Application. A concrete example I would give from my point of view could be: do not store images in a DB, but rather the path to them, because you can have them served them by the web server, which can apply all of its caching issues.
But in a desktop environment, especially in iOS application, what are the downside of having stored in Core Data using sqllite, providing that:
There’s a separate entity holding the images, it is not an attribute
of main entity
Also seems to be a limit of 100kb for images. Why ? What does happen with a 110,120…200kb ecc ?
- How do I set default values on new properties for existing entities after light weight core data migration?
- NSManagedObject subclasses duplicate declaration
- Core data transient values with Swift
- Debug Core Data Migration to compare hash values
- Preventing a CoreData crash for upgrading users
- Deleting core data version xcdatamodel files
3 Solutions Collect From Internet About “Provide example for why it is not advisable to store images in CoreData?”
There’s nothing special about what Core Data normally does here. It’s just using an SQLite database. You can put large blobs of data into it, but it just doesn’t scale all that well. You can read more about it here: Internal Versus External BLOBs in SQLite.
That said, Core Data has support for external blobs which in Core Data terminology is called stored in external record (iOS 5.0 and later). Again, there’s nothing magic about it, it’s just storing the large pieces of data in the file system separately from the SQLite db itself. The benefit is that Core Data updates all this for you.
When you’re in Xcode, there’ll be a checkbox called Allows External Storage that you can check for Binary Data properties.
The filesystem, and the API:s surrounding it is (just like a webserver) optimized to serve files, of any size, and to apply caching where appropriate.
CoreData is optimized for handling an object graph with tiny pieces of data, like integers and short strings.
Also, there are a number of other issues that tend to creep up on you, like periodically vacuuming the SQLite database CoreData uses, or it won’t be able to shrink, just grow.
With Lion/iOS 5, Core Data started handling file system storage of large BLOBs for you.
The choice is really determined by how many images you are going to have open. If you have many, then you should keep them in the DB. Why? Because you only have a modest number of file descriptors, one of which is used for each open image stored in the file system.
That said, there is still a reason to manage the files yourself. If your BLOBs are really big, say 2+ MB, you will want to map them into memory and not just read them in. (When the memory warnings come, this lets the OS automatically purge them from your resident memory. This is a very good thing.) Even so, you still have the limited number of file descriptors problem.
- Sort NSArray of custom objects by their NSDate properties
- Filter by array of Objects searchController
- Comparing Strings in Cocoa
- Xcode 6.4 showing duplicate 'Simulators' with Unique Id
- How to call a method when the Done Button in the KeyBoard is Clicked?
- keeping a UIButton pressed(state selected/highlighted),until another button is pressed?
- Error: unrecognized selector sent to instance
- Using Instruments to Work Through Low Memory Warnings
- Child View Controller shifts down
- UITableView Edit mode
- Minimum Xcode version to upload to App store (As on February 2016)
- Global constants in Objective-C
- How to do string conversions in Objective-C?
- Adding View Programatically With Auto Layout Gives 'NSGenericException', reason: 'Unable to install constraint on view
- Audio playback progress as UISlider in Swift