Created
August 14, 2015 23:20
-
-
Save c9iim/a8888875dd1e8b08a3ac to your computer and use it in GitHub Desktop.
ユーザー定義に依存したプロトコル拡張例。依存部分の初期設定は拡張外の責務。
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 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