Created
July 3, 2023 15:03
-
-
Save zilmarinen/5b58ae4a2cbc27e34215553be7687a9e to your computer and use it in GitHub Desktop.
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 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