Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zilmarinen/5b58ae4a2cbc27e34215553be7687a9e to your computer and use it in GitHub Desktop.
Save zilmarinen/5b58ae4a2cbc27e34215553be7687a9e to your computer and use it in GitHub Desktop.
protocol SizeDescriptor {
var width: CGFloat { get }
}
protocol ColorDescriptor {
var color: String { get }
}
class MyView {
public let descriptor: SizeDescriptor & ColorDescriptor
init(descriptor: SizeDescriptor & ColorDescriptor) {
self.descriptor = descriptor
}
}
class MyAwesomeView {
public let descriptor: SizeDescriptor
init(descriptor: SizeDescriptor) {
self.descriptor = descriptor
}
}
enum Sizes: SizeDescriptor, ColorDescriptor {
case small
case large
var width: CGFloat {
switch self {
case .small: return 10
case .large: return 100
}
}
var color: String { "babyfood_orange" }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment