Skip to content

Instantly share code, notes, and snippets.

@hitendradeveloper
Last active December 6, 2019 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hitendradeveloper/ae404a8b7801c7b24079abbcc7c562f6 to your computer and use it in GitHub Desktop.
Save hitendradeveloper/ae404a8b7801c7b24079abbcc7c562f6 to your computer and use it in GitHub Desktop.
// Hitendra Solanki
// Pure-singleton design pattern Playground example
final class LogManager {
//shared and only one available object
static let logger: LogManager = LogManager(databaseURLEndpoint: "https://www.hitendrasolanki.com/logger/live")
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
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment