I am building an application that recovers JSON data (1000-2000 lines) from a website. It's basically just a bunch of arrays and values, nothing fancy. What would be the best way to store this information and use it between the views? Should I create a local sqlite database, write to file or just send the information from view to view using prepareforsegue?
I would think the latter is faster and easier to implement, but I'm not sure if it's easier to use after (I'm new to IOS).
Thank you !
I'm using Core Data with Magical Record. It easily maps your JSON objects into NSObjects which are then persisted into Core Data. It is thread safe and very powerful.
Or you can map it yourself into NSObjects of your choice without actually persisting them or saving them anywhere which is much easier in some cases. It is a good way to go as well.
Both methods looks OK . Now it depends whether your JSON data is big enough to slow down the app.
Sqlite Database is easy to implement to store large information in your app.but if you want to increase performance of app to access data locally you can use core data to store data because it providing object relationship to store data in app that is easy to access and store data.but now it is depends on you
Related
So I have an iOS app and this JSON file (about 50 MB) that has a deep tree structure. The goal is to store this file locally and use its content later on the app, with the possibility of updating the data or some parts of it in the future..
After some research, I found out that I can use core data, but it seems inconvenient for such complex structure.
So, I thought maybe I'll persist the data in a class object, but this may end up consuming the whole mobile memory.
Now, I'm thinking if it is plausible to store the data in a plist then map the hell out of it to present its content.
What do you think guys? Do you have any other ideas or thoughts?
Just store the JSON as you received it, as NSData. It doesn't care one bit about the structure, so you can parse it again.
After a lot of research and reflexion, I ended up using Realm for its simplicity and effectiveness.
Background:
I have an app that retrieves a list of restaurants from a database, each have an individual array of basic information about them (hours, name, address, etc). I would like to retrieve that information from the server on the apps first load, but then have it stored within the app itself, with either NSUserDefaults or Core Data, since the information is unlikely to change. The max number of restaurants I would be storing is about 25, is that a small enough data collection to use NSUserDefaults?
I have looked at similar questions with storing data with over 1,000 records, but I am only storing a small array.
Question:
NSUserDefaults is much easier to use than Core Data, so if possible I would like to avoid using Core Data. In my case, will there be a performance problem if I am storing my list of restaurants in NSUserDefaults instead of Core Data?
Depends on the
size
structure of data
requirements re integrity of the data
Just an Array of 10 or 20 "restaruants" I would certainly store in NSUserDefaults. But only when I am sure that this will never become more complex. Because when you later extend your model but started off with NSUserData then you may remain with NSUserDefaults just because you avoid migrating it to Core Data during the upgrade of an installed app.
So for more complex structures including references and when you have further plans with your app towards more functionality that may require more entities, then you should go for Core Data from start.
BTW, it is not that complicated as you may think.
However, instead of abusing NSUserDefaults, you could simply write an NSArray to file using -writeToFile:atomically: and -initWithContentsOfFile: to read them in.
NSUserDefaults is not intended for data, it's for storing simple key-value pairs like user settings and flags. Core Data is a bit hard to learn at first, but definitely worth it, even for simple applications.
If it really is a small, simple data set that won't change very often, you can also store some data in a local plist (i.e. save NSArray or NSDictionary to plist using writeToFile method). This isn't very different from using NSUserDefaults in terms of performance, although I think it's cleaner and easier to manage. If it never changes you can also include the plist with your app resources in XCode by creating a plist file and filling it in with your data.
Considering the amount of the data, user default or a specific plist/json file are all good. CoreData is definitely overkilling.
I'm creating an iOS application that has a Twitter-like feed of data. I'm currently planning on storing the data on Parse. However, what is the most efficient way to store retrieved objects locally for use when there does not exist a network connection? It sounds like using Core Data is overkill since I'm storing the data on Parse anyway. Can the Parse caching system do this for me or is there something else more appropriate? On a similar note, is there a simple way to check if this locally saved data is up-to-date?
I recommend you have a look at SQLite, especially with the FMDB Objective-C wrapper classes.
Parse has the capability to cache objects locally. If your app can tolerate the characteristics of caching, then just use that.
My own app will not, so I am using CoreData as my local store. My app has to be able to operate fully when disconnected from Parse, so I have to have something more than cached data. I looked at FTASync and found the concept very useful. When I got into the code though I realized I needed something much more robust, so I have ended up doing a completely new utility to sync Parse with CoreData. This is a huge job, so don't take it on unless your need is commensurate.
-Bob
I'm just getting started on making a board game using Cocoa/Objective-C. My plan is to first get it functional as a Mac OS X app, and then port it to iOS.
I saw something in the documentation for the Core Data API that made it sound like it was the recommended way to store data persistently, and made reference to the fact that iOS apps should be able to quit and be restored in exactly the same state. I got the initial impression that I should plan to use Core Data for any variable that has to do with the game's state to support this.
But as I'm learning more it seems like my initial impression isn't correct. Core Data seems more like something intended to provide similar features as embedded SQL, and is more complicated than is required just for storing the game state persistently on disk. Is there a simpler way to support fast app restoring in iOS apps, or is Core Data the way to go?
Core Data is fantastic for storing lots of data of different types, including custom objects.
However, if you're talking about storing things like high scores for a game or other simple int, float, BOOL, NSString, NSArray data, then for iOS NSUserDefaults is a quick and easy way to go.
Core Data lets you store data as objects, so if your game state can be described with native data types, Core Data just might work for you. You'd essentially be manipulating object states.
If you're looking for something a little more lightweight, look into the NSUserDefaults API (which is the same thing that the Settings App on iOS uses).
Alternatively, you could come up with your own format and use that, serializing your own data to disk.
I'd start with NSUserDefaults.
There are various ways for iPhone applications to save data (for example: NSUserDefault, XML, document, SQLite, etc.).
Our company always uses NSUserDefault to save data. However, I don't think NSUserDefault is very good because in my experience, it has been slow.
I am curious how you store data for your applications and when you recommend using each of the different methods. Please share your experiences that will help me to understand the advantages and disadvantages of these different storage types and develop a more efficient application for my users.
You can store small data in NSUserDefaults but when you have large database then you need sqlite or coredata for storing the database. use of coredatabase is good for big database this is provided by apple and it is to efficient in accessing database.
NSUserDefaults or document directory is used for small database(suppose need to store user name for single user or some other info).
You just need to know about sql queries to store data in a SQLite3 Database or You can use Core Data for back end storage. Core Data is one of the best options to use for storing data.
NSUserDefault should be used for storing small information.
You can use NSUserDefaults for storing any small data which you want to persist when your application closes. This you can use to store login details but yes if it is be secured, use keychain. You can definely use NSUserDefaults for storing setting options.
SQLite database is any easy way to store large data. Core Data is best option. but you can use SQLite if your application data is not too large.
SQlite Database can also be used to store BLOB data e.g. to store pdf file bytes downloaded from server and whenever you want to use it, just write those bytes to pdf file. This will also keep data security since BLOB data in SQLite cannot be viewed.
Its good to use coreData for large data storage in the IPhone Memory space. ITs a wrapper on top of the database which helps us to store in the form of objects.....
U can find many examples on this...