Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm starting an app in iOS which will use a SQLite database.
I would like to reuse the code of this app for others in future.
I would like to make first a view associate to a ViewModel.
I will use a repository for my data. First, it will be generate, and after, data from SQLite database.
Then, when I'll use the database, just change some stuff in my ViewModel and all will work good...
I don't know if you see what I mean...
Do you know some good practices to do this? Tutorials, explanation, or anything else interesting?
EDIT:
I would like to follow this way:
Repository can be database data or random generated data for testing before I have the database...
ViewModel is the "model of myt view" which set all objects of my view with the data fetched in my Repository...
I understand the idea, but I don't know how to proceed to do this and I found nothing about the method... Maybe it's not a good way ?
If you have any suggestion, please let me know ;) Thank you!
Make an object class for the interaction with the sqlite, Preferred will be a singleton class which could also be used as intermediary storing class.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm learning Swift and I have a question about data model or the Model folder in Xcode. During a project 'Quiz app' we opened a new swift file in Model folder and started to write some code in it.
What is Data model and why instead of writing all the code just in the ViewController file we need to write a separate one in the model folder?
You could, technically, have all the code for your app in a single file. But it would quickly become really hard to find somethig and keep it readable. Also, when working in bigger teams, having a lot of code in few files results in merge conflicts, which could quickly get out of hand.
It is simply a good practice to keep all your classess in separate files, grouped in folders.
As for what a „data model” is - it’s just a representation of your domain problem in code. These classess will most likely represent data you retrieve from web, or create in app to perform some further operations on them or to use them as input for views to present them to the user.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I would like to know what are the best practices regarding, Modeling data when no network connection available, if the app you are building is cloud computing based, but still you want to be able to have basic functionality and I guess some persistent data?
PD: I am kind of new to IOS development
UserDefaults is okay for small bits of data that don't change often, but as it has to rewrite the entire user defaults dataset to a file each time a change it made, it is not robust enough for anything of volume or with frequent changes. For that you would want CoreData or a third party open source solution like Realm.io.
You can try to using the 'cache' where you store temporary data.
One way to achieve this is NSUserDefaults where you set a variable (let's say users profile photo) and when the user opens his app again, the image will be loaded even if there is no internet connection since its cached. Hope this helps!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm developing an iOS app that is going to parse XML from an RSS feed of events and display the details of each event on a table view. Each event has a title, a description (optional), a date and a time. I am able to parse the XML data using NSXMLParser; however, I am not sure how I should store the data and make it so that it persists after the app is closed.
I have read that I can use NSCoder to persist the data but I am not sure if this is the best route forward.
Does anyone have any ideas or suggestions as to what I could do?
Any help is appreciated.
You have several options for persisting data.
NSUserDefaults are meant for user settings - small amounts of data. They seem unsuitable for what you have in mind.
NSCoding is quite a good way to store structured data without the overhead of a database, yet it is slow in comparison to core data.
Core Data is Apples ORM, which is quite powerfull but not as easy to wrap your head around.
I answered a similar question recently, which goes into more detail regarding NSCoding with a complete example and some links for further reading.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I want to create a searchable database in Xcode - for example, of different trees. The database would consist of the tree name, two images, price, and a short description. What is the best and most efficient way of creating such a database?
I am aware of: Core Data, SQLite3, and Parse. I am leaning towards SQLite3 but have not found a good place to learn how to implement this. Any suggestions?
Seeing as you are new to Objective-C and I doubt this will evolve into something need direct SQL I would suggest using CoreData. Although it is not technically a data base it is an object graph, it is built for exactly what you are wanting to do. Apple was even nice enough to build wrappers for everything you want to do.
CoreData to store your tree name, two images, price, and a short description.
NSFetchedResultsController for grabbing it.
UISearchBarController for letting the user search.
You would want to use Parse if you wanted to save your data to a server. If your doing everything locally I wouldn't worry about Parse. CoreData is what you want.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
In my application, I want to have a "brain" that keeps track of what's going on. That is - multiple view controllers need to be able to set values in this brain and get at its data too.
How would I go about implementing this? From what I can tell, making my brain a singleton class is an option, otherwise I'd have to declare the brain as a delegate in every view controller and assign the brain to it every time it's created, which seems quite messy.
Your answer is in your question as you said. Use Singleton pattern if you want to access an object from multiple objects and there is no need for more than one copy.
Bear in mind that you must keep your data thread-safe if you will have two or more objects in your code that will try to manipulate the "brain" at the same time.
As for the Singleton pattern, you might like to read this What is so bad about singletons?
Make sure you design your app using the MVC pattern and you should be good. The "brain" is the model.
How your "model" behaves depends on your application.
Singleton pattern is an option. Another option is NSUserDefault.
Yes you are right Singleton is a good option.
As i think you are dealing with low amount of data so singleton will be good and easy otherwise go for saving data in a database or NSuserDefaults.