Swift-单例

2022-05-07  本文已影响0人  iVikings
@objcMembers
public class Singleton: NSObject {
    public static let shared = Singleton()
    
    private override init() { }
    
    public override func copy() -> Any {
        return self
    }
    
    public override func mutableCopy() -> Any {
        return self
    }
    
    // Optional
    public func reset() {
        
    }
}
class Singleton {
    
    static let shared = Singleton()
    
    // Make sure the class has only one instance
    // Should not init outside
    private init() {}
    
    // Optional
    func reset() {
        // Reset all properties to default value
    }
}
上一篇 下一篇

猜你喜欢

热点阅读