Created
September 25, 2023 20:53
-
-
Save willie-hung/292516186e110343b43d180c37f71cc7 to your computer and use it in GitHub Desktop.
iOS Interview Prep 4- Singleton pattern
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
class DatabaseManager { | |
static let databaseObj = DatabaseManager() | |
private init() { | |
} | |
func checkDatabaseAccess(user: String) { | |
if user == ("Sung-Jie") { | |
print("Access Granted!") | |
} else { | |
print("Access Denied!") | |
} | |
} | |
} | |
let userName = "Sung-Jie" | |
let database = DatabaseManager.databaseObj | |
database.checkDatabaseAccess(user: userName) | |
// Console output: | |
// Access Granted! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment