Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// Hitendra Solanki
// Pure-singleton design pattern Playground example
final class LogManager {
//shared and only one available object
static let logger: LogManager = LogManager(databaseURLEndpoint: "")
private var databaseURLEndpoint: String
//marked as private, no one is allowed to access this initialiser outside of the class
private init(databaseURLEndpoint: String) {
self.databaseURLEndpoint = databaseURLEndpoint
func log(_ value: String...){
//complex code to connect to the databaseURLEndpoint and send the value to server directly
//This is function in playground which executes our test code
func main(){
LogManager.logger.log("test log from medium blog") //this will log on "/live" endpoint
//call main to execute our test code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.