开发者

Class specific data

using xcode I would like to achieve a public shared class that stores its own data. So, if I'm in one class I can call it from another and retain persistence.

For example,

I have multiple viewcontrollers for an iPhone project. When the app is opened, it checks with a seperate service if that player is logged in and returns some information. Let's call it GamePlacenta. I need t开发者_JAVA百科o store certain information about the player in the GamePlacenta class, like user_id etc. But I need to be able to access it from any other class later on. I don't want to store it in text files, memory is good.

What do I need to be looking into?


You need to use a Singleton. It does exactly what you want it to--holds one set of data that you can access anywhere. Here is a great tutorial on creating one. It's just a few lines of code, and can store anything.


Sounds like you need a Singleton class. See this Wikipedia article.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜