Skip to content

Instantly share code, notes, and snippets.

@c9iim
Created August 14, 2015 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save c9iim/a8888875dd1e8b08a3ac to your computer and use it in GitHub Desktop.
Save c9iim/a8888875dd1e8b08a3ac 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