Skip to content

Instantly share code, notes, and snippets.

@fromkk
Last active February 3, 2018 09:15
Show Gist options
  • Save fromkk/c079d1a281762260b145b727371a0f9e to your computer and use it in GitHub Desktop.
Save fromkk/c079d1a281762260b145b727371a0f9e to your computer and use it in GitHub Desktop.
protocol AnyGetableAndSavable {
associatedtype T
func get() -> T
func save()
}
class GetAndSaver<U>: AnyGetableAndSavable {
typealias T = U
var value: T
required init(value: T) {
self.value = value
}
func get() -> U {
return value
}
func save() {
//save
}
}
class Hoge {
var getAndSaver: AnyGetableAndSavable = GetAndSaver<Int>(value: 1)
// protocol 'AnyGetableAndSavable' can only be used as a generic constraint because it has Self or associated type requirements
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment