Skip to content

Instantly share code, notes, and snippets.

@bppr
Last active May 24, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bppr/29eb34ef1638d97b883c6839fcfb229d to your computer and use it in GitHub Desktop.
Save bppr/29eb34ef1638d97b883c6839fcfb229d to your computer and use it in GitHub Desktop.
swift protocols with associations
protocol Features {}
protocol ProFeatures: Features {}
protocol Account {
associatedtype FeatureType
var features: FeatureType { get set }
}
class ProAccount<T: Features>: Account {
typealias FeatureType = T
var features: FeatureType
init(features: FeatureType) {
self.features = features
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment