Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //: # Feature Flag example
- //: ## Implementation
- import Foundation
- enum Feature: String {
- case Login, AdminTool
- var key: String {
- return "FEATURE_FLAG_\(rawValue.uppercased())"
- }
- var isEnabled: Bool {
- guard let flag = ProcessInfo().environment[key] else { return false }
- return flag == "on"
- }
- func toggledOn(block: ()->()) {
- if isEnabled {
- block()
- }
- }
- func toggledOff(block: ()->()) {
- if !isEnabled {
- block()
- }
- }
- }
- //: ## Usage Example
- Feature.Login.toggledOn {
- print("do this if feature is on")
- }
- Feature.Login.toggledOff {
- print("do this if feature is off")
- }
Add Comment
Please, Sign In to add comment