Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save uchcode/223f0eb7d5fa95d48f7a3b45a7689e33 to your computer and use it in GitHub Desktop.
Save uchcode/223f0eb7d5fa95d48f7a3b45a7689e33 to your computer and use it in GitHub Desktop.
ユーザー定義に依存したプロトコル拡張例。依存部分の初期設定は拡張外の責務。
//: ユーザー定義に依存したプロトコル拡張例。依存部分の初期設定は拡張外の責務。
protocol FooSpec {
var fizz : Int { get }
func buzz() -> Int
}
extension FooSpec {
func buzz() -> Int {
return fizz * 2
}
}
//
struct Foo : FooSpec {
let fizz : Int
init(fizz: Int) {
self.fizz = fizz
}
}
let const = 1
let bar = Foo(fizz: const)
assert(bar.buzz() == const * 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment