/enums_extensions.swift Secret
Last active
November 16, 2017 14:07
Enumeration with two extensions
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
protocol Taskable { | |
func execute() | |
var description: String { get } | |
} | |
protocol Serializable { | |
func serialize() | |
} | |
enum LayerActions { | |
case scale(width: Double, height: Double) | |
case rotate(degrees: Double) | |
case fill(hex: String) | |
} | |
extension LayerActions: Taskable { | |
func execute() { | |
switch self { | |
case .scale(let width, let height): | |
print("Executes scale action") | |
case .rotate(let degrees): | |
print("Executes rotate action") | |
case .fill(let hexColor): | |
print("Executes fill action") | |
} | |
} | |
var description: String { | |
switch self { | |
case .scale(let width, let height): | |
return "Scales the layer to \(width)x\(height)" | |
case .rotate(let degrees): | |
return "Rotates the layer \(degrees) degrees" | |
case .fill(let hexColor): | |
return "Fills the layer with \(hexColor) color" | |
} | |
} | |
} | |
extension LayerActions: Serializable { | |
func serialize() { | |
// Code that serialize the enum into a json file | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment