开发者

Objective-C Singleton Category for internal use of NSCalendar

I have a two part question. First, how can you create a Singleton category in Obj-C? It would just be for internal use so it does not have to be foolproof singleton. Secondly, can I create this category on NSCalendar and have the singleton be an autoupdatingCurrentCalendar? Is this safe considering a user might change timezones while using the application? I want to avoid creating an instance of NSCalendar e开发者_JAVA百科ach time I need one (since it is used for a tableviewcells) but I don't want to have timezone problems.


"singleton category" doesn't make any sense... A singleton is a class that can be instantiated no more than once. Categories provide a way to extend classes, but don't give you any particular control over how many times the class is instantiated.

It sounds like you really just want a shared instance of NSCalendar. If that's the case, then you can certainly declare a global variable and create some class methods in a category that give you access to that global variable.


autoupdatingCurrentCalendar is already a singleton, so I don't see the point of creating a category for that. As for creating singleton categories – sure, that's possible, pretty much the same as a regular singleton.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜