Last active
December 6, 2019 22:29
-
-
Save hitendradeveloper/ae404a8b7801c7b24079abbcc7c562f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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