How to make a Swift Class Singleton instance thread safe?
问题 I have a singleton class as so: class Database { static let instance:Database = Database() private var db: Connection? private init(){ do { db = try Connection("\(path)/SalesPresenterDatabase.sqlite3") }catch{print(error)} } } Now I access this class using Database.instance.xxxxxx to perform a function within the class. However when I access the instance from another thread it throws bizarre results as if its trying to create another instance. Should I be referencing the instance in the same