Last active
May 24, 2019 15:41
-
-
Save bppr/29eb34ef1638d97b883c6839fcfb229d to your computer and use it in GitHub Desktop.
swift protocols with associations
This file contains hidden or 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 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