Created
February 15, 2023 21:02
-
-
Save foxicode/833e43c644f9a272d6e26c94b3c5891f to your computer and use it in GitHub Desktop.
Existential Any
This file contains hidden or 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
| import Foundation | |
| protocol User: Identifiable { | |
| var firstName: String { get set } | |
| var lastName: String { get set } | |
| } | |
| func printUserName(_ user: any User) { | |
| print("\(user.firstName) \(user.lastName)") | |
| } | |
| enum AdminRole { | |
| case manager | |
| case finances | |
| case support | |
| } | |
| struct Admin: User { | |
| // Identifiable | |
| var id: Int | |
| // User | |
| var firstName: String | |
| var lastName: String | |
| var roles: [AdminRole] | |
| } | |
| let admin = Admin(id: 1, firstName: "John", lastName: "Doe", roles: [.manager, .finances]) | |
| printUserName(admin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment