Last active
February 3, 2018 09:15
-
-
Save fromkk/c079d1a281762260b145b727371a0f9e 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 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