Cocoa Singleton Agreements

Cocoa is full of singles. Is there a logical / conditional difference between when the Cocoa API uses

NSSingletonObject *so = [NSSingletonObject defaultSingleton];

against

NSSingletonObject *so = [NSSingletonObject sharedSingleton];

?

Not a huge thing, but I really don't understand why sometimes one is used compared to the other.

+3
source share
1 answer

I think it is, as a rule, that if it's a real singleton (eg, NSApplication ), which you use -[JKFoo sharedFoo]. If, on the other hand, the class provides access to the default instance, but you can still create other instances (such as NSNotificationQueue or NSFileManager ), then the convention is used -[JKBar defaultBar].

: Cocoa, OpenSource, :)

[edit: GCD blog]

+7

Source: https://habr.com/ru/post/1747034/


All Articles