I\'ve been trying to implement a singleton to be used as a cache for photos which I uploaded to my iOS app from the web. I\'ve attached three variants in the code below. I
Swift-5
To create a singleton class:
import UIKit final class SharedData: NSObject { static let sharedInstance = SharedData() private override init() { } func methodName() { } }
To access
let sharedClass = SharedClass.sharedInstance
OR
SharedClass.sharedInstance.methodName()