Created
May 7, 2019 14:35
-
-
Save superarts/7364f376b93f516b46f2f27a121b7268 to your computer and use it in GitHub Desktop.
Pure Functions in Swift Enum
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
protocol PureEnumProtocol { | |
func test() | |
} | |
enum PureEnum: PureEnumProtocol { | |
static var v = 1 // Still possible | |
//var v = 1 // Enums must not contain stored properties | |
func test() { | |
//v = 2 // Impossible | |
print("PureTest", PureEnum.v) | |
} | |
// Redundant stub initializer is needed | |
case pure | |
init() { | |
self = .pure | |
} | |
} | |
let pureEnum: PureEnumProtocol = PureEnum() | |
pureEnum.test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment