I have a situation where I may need to declare two singletons in a class
class ImageManager {
static var imageCache = NSCache()
static var imageManager = ImageManager()
(...)
}
Is there any danger to this ?
Generally, there is no problem with multiple static variables in a single class. Only one of them should be called singleton - namely, the imageManager, because that's the instance that's going to be unique in your design.
However, if ImageManager need the exclusive use of NSCache, it is better to make imageCache an instance property of ImageManager. Should other static methods need to access the cache, they could always gain access to it through imageManager.imageCache.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With