While I have been working with iOS apps for some time now, I am totally new to core data. So, just have a simple question.
Can images be cached and stored in core data?
I could not find any sample app for caching images into core data. It would be of great help if someone can share me links for image caching in core data in case this is possible.
[P.S I know image caching. So, not looking for links or samples for only image caching. Please share info on image caching with core data]
You can take a look at this article.
But IMO it's better to just store imageURLs in your Core Data database and cache them with setImageWithURL:placeholderImage: (AFNetworking awesomeness).
Check one of the below tutorials:
Core Data Image Caching
File System vs Core Data: the image cache test
USING COREDATA TO CACHE AND DISPLAY IMAGES VIA INSTAGRAM
Related
I have many form in my application I want to store data locally when net is not available.
and if net is available then send to server.
please let me know how to implement this.
Thanks
You can use Core Data, SQLite with FMDB, plist serialisation of just plain and simple NSCoding.
You can use core-data to store the data locally for iPhone.
Introduction to Core Data
SQLite is also good but i`ll prefer core data.
I am working on an iOS app. Client side is written in Swift.
I want users to be able to store text and images in a local DB, and then transmit the DB records to a server.
I already implemented client-side data storage (but not for image files) using SQLite DB. I know that it is possible to store image files as BLOBs in SQLite, but is it wise to do so? What are your experiences? If SQLite is not the right DB for this use case, what would be better?
This StackOverflow answer discusses why saving an image in a database isn't the greatest idea.
I think the current best practice for saving images on iOS would be to save the image to documents or the photo album, and save the file path to the image in the DB. UIKit has UIImageWriteToSavedPhotosAlbum() which will save the image for you.
I'm starting a new project (and very new to Core Data) and was curious about how to manage images within Core Data and an Asset Library. I've done some reading and am just unclear on how everything works together.
Is it possible for each Managed Object to have an "asset library" of images? ie. can the asset library be populated with Core Data data.
What is the best way to handle having a large array of images attached to a managed object?
If anyone can point me in a direction of an article/tutorial or provide further guidance, that would be greatly appreciated.
Thanks!
Yes Core Data can handle storing an image asset database as well as the images themselves. Core Data has an option that will let it store large binary objects as files, rather than in the sqlite database itself. Core Data would be effective for storing details about the images and for categorising them into albums, projects etc.. It would also be useful for searching on these attributes.
Typically you would not attach a large array of images to a managed object. An image would be represented by a managed object and one of the attributes of the managed object would be the image (which Core Data might decide to store as a file somewhere).
I think you might be out of luck if you want to use iCloud for replicating this image library because I don't think Core Data will sync these externally stored image files.
https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS5.html
Managed objects support two significant new features: ordered relationships, and external storage for attribute values. If you specify that the value of a managed object attribute may be stored as an external record, Core Data heuristically decides on a per-value basis whether it should save the data directly in the database or store a URI to a separate file that it manages for you.
if you store your images in image assets and Managed Object have the "asset library" of images, then you will have the problem on updating the images.
and even if you do not want to ever update the images then why to store it in core data ?
solution is : have the images in image assets and also store the binary data of images in core data in launching the app.
by checking a date of modified coming from a web server you can check whether to update the images or not.
this link is helping you to import anything to core data easily done.
I have a bug in my iPad app where it's not either saving or retrieving the correct image from a Core Data store. So, when using the Simulator I need to have several distinct small images in each entity so I can see what's going wrong.
Is there a way to get an image into the Core Data store on the Mac? (I don't care what they look like, as long as they are different from any of the others). I did a search in Google and SO and found nothing appropriate.
Can you not use the way those images are parsed into Core Data in your app? That will give you a persistent store containing those images from which you can then retrieve them later.
I'm developing an app that uses core data (with UIManagedDocument) for storing user-generated data that I would like to sync with iCloud. I also would like to sync photos that the user takes with the camera within the app.
I read that it's not a good idea to store the actual photos within core data; rather it's better to store the photos in the file system and put the fileURL in core data.
Using this method, what is the recommended approach when using UIDocument to store the photos in the file system (under the Documents folder)?
I've thought about:
For each individual photo, use a NSFileWrapper(containing the
actual image and thumbnail image), or
Use a top-level NSFileWrapper, and put all NSFileWrappers in it for each photo
Similar to #2, but just put all photos/thumbnails directly in the top-level NSFileWrapper
Which approach is better for syncing photos with iCloud? and are there better approaches?
The best approach in this case is to let Core Data decide where to put it.
Open your Core Data model GUI -- click on your attribute that will hold your binary data -- look to the right -- there is a check box that indicates if Core Data should use external storage if it wants. Select it.
That's all. If Core Data needs to use external storage, it will do so -- you wil neither know nor care what it decides.