开发者

Use of singleton class and sqlite

开发者 https://www.devze.com 2023-02-14 03:46 出处:网络
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 c开发者_Go百科orrect/possible/doable to do so, any advise would be app

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 c开发者_Go百科orrect/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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消