Singleton with Swift 3.0

前端 未结 6 1664
灰色年华
灰色年华 2021-01-15 04:33

I had this implementation with Swift 2.0 and the Xcode suggestion is not only baffling but causes compilation error as well. it\'s a library where users are passing callfunc

6条回答
  •  醉梦人生
    2021-01-15 05:08

    Another way, for me which is good enough using init private

    final class SingletonClass {
    
        // reachable from other classes
        static let sharedInstance: SingletonClass = SingletonClass()
    
        // properties
        var stringArray : [String] = []
    
        // not reachable from other classes
        private init() { }      
    
    }
    

提交回复
热议问题