Question

Im new to objective-c and I've been reading up on singleton classes. I want to implement it into my logic but im not sure if its correct/possible/doable to do so, any advise would be appreciated.

At the moment i'm loading data from an xml feed, but i want to have control what data should be displayed based on which button is clicked. For example, buttonA would display IT news and buttonB would display celebrity news.

My thinking is to load the xml data into sqlite on application start in the background and display my buttons view at the same time using the singleton class. If the user pushes the button it will query the required table and display the content into a tableView.

Is this viable? If not, could you please advise whats the best way to go about this?

Thank you.

Was it helpful?

Solution

First of all you should reconsider organization of your data model. You've named sqlite on one hand and a global array on the other.

I would point you to Core Data to store your parsed data in a convenient way. Finally all you need is to query the Core Data db and fetch what you need. This would be more memory efficient than storing your data in a global array.

Have a look at Apple's Core Data tutorial or at this nice turorial: "superdb-core-data-app-with-sections"

To share a managed object context you can use a singleton. Have a look at this blog post, it provides a solution without a singleton by passing references of the managed object context down the relevant objects. It is created in the app delegate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top