I have a local database implemented in my iOS app using Core Data that is populated from a backend driven by Parse.
I want to have a Core Data entity that has as an attribute a PFFile (a parse file object). Core Data doesn't support PFFiles but it does support NSData.
How could I get a NSData representation of my PFFile?
Call getDataInBackgroundWithBlock: on the file.
Note that storing the data on disk and storing the path you saved it at is usually a better idea than storing the data in Core Data.
Related
I was trying to Store data offline by using firebase database reference. I read documentation and it say one line code will store everything.
Database.database().isPersistenceEnabled = true
But this line only store text. It's not storing image offline.
isPersistenceEnabled is only storing your text content. if you want to save image you need to use core data. Core data is little bit hard to save large file. i would recommend to use NSfileManager to Store your image.
Hope it will help .
Do you want to send data after you will be connected to WiFi? So you can store your data to CoreData and after you will be connected to Wifi send it to Firebase storage
Now I save the cache in NSUserDefaults. As before, I used the small array, the NSUserDefaults for me. Now when you save large array in NSUserDefaults application freeze. What are the alternatives to the cache arrays in objective - c for iOS?
UPDATE:
I want to save 30-60 HTML file into an array. and then the array cache. Stores an array to NSUserDefaults long. that is better for me to use? the database? nscache? if a database, what?
You can write the HTML data as NSString into a NSDictionary and save it in a .plist file in the documents directory. You would be able to edit, append and delete your data as you want using this approach.
If you are looking for a caching pupose,you can use NSCache and iOS manages the memory.But its not guaranteed the availability of data always.iOS may remove data and free up the memory because of memory warning.
If your data is higher in size,you should save the data to document directory instead of directly saving to RAM (Saving to Objects use RAM memory).Write data to a file or use plist.
My program uses Restkit with Coredata.
I need to persist 3 entities in the local storage so that I don't have to download a huge payload every time I need the data.
I also need the data to be refreshed when I want. The data should be refreshed in a way that only the changed objects will come through.
What is the best practice to do so in a system with CoreData and Restkit?
I see that Restkit used to have a RKSyncManager but not anymore..
My situation is that I have a universal app that talks to an sql database via odata. When the user retrieves data over the line I want to save that to the device so that if the user stops the app or the app crashes than I can rehydrate the saved device data and we will not have to re-retrieve the data when the app starts again.
My question is for this sitatuation is it more beneficial to user coredata to save the data to an sqllite db or should I save the data to the documents directory? The data can be serialized into an NSData object which could be saved straight to the device from what I have read, where as saving NSData objects to sqllite is not what it is designed for.
Im looking for the most performant of the two options and also the option that will not restrict as much on size restrictions.
Looking forward to any advice that you can give me.
Thanks in advance
If the size of the data is small enough to fit in memory with no problems, then you will probably get the best performance from serializing an NSData object.
If, however, the data reaches the point where it strains memory usage, you will want to use something like Core Data or sqlite to persist it to the disk and only load objects in memory you are using at the moment.
I saw in other posts that it is O.K to store small image files (less then 50 kb) as a binary data inside core data. is it true for sound files that are less then 20 kb?
Thanks
Shani
There's no difference between sound files, image files or any other binary data as far as Core Data is concerned. Under 20kB I would store in Core Data unless you have a good reason not to (such as caching as mentioned), but I would store them as a separate entity if you are not accessing them every time you access an object.
The general rule of thumb I've seen mentioned is <10kB store on the entity, >10kB but <100kB store in a separate entity and >100kB store in the file system.
I store data like this in the file system and I keep the path to the file in my core data object. This lets me optionally use a class that caches lookup of the images that can be emptied if the program receives memory warnings.
You should read the apple's "Core Data Performance" document, specifically the section on Large Data Objects.