Skip to content

Instantly share code, notes, and snippets.

@hiragram
Created August 5, 2015 00:24
Show Gist options
  • Select an option

  • Save hiragram/7d64eef4369bdbd86c12 to your computer and use it in GitHub Desktop.

Select an option

Save hiragram/7d64eef4369bdbd86c12 to your computer and use it in GitHub Desktop.
#!/usr/bin/swift
/**
$ swift -v
Apple Swift version 1.2 (swiftlang-602.0.53.1 clang-602.0.53)
コメントアウトしたりしてどの関数が実行されるか見てみる
A,B,C -> A
A,B -> A
A,C -> A
B,C -> Error
./trailingClosure.swift:30:1: error: ambiguous use of 'anyFunction'
anyFunction("fuga") {
^
./trailingClosure.swift:22:6: note: found this candidate
func anyFunction(message:String, extra:String? = nil, completion:()->Void) {
^
./trailingClosure.swift:26:6: note: found this candidate
func anyFunction(message:String, extra:String? = nil, moreExtra:String? = nil, completion:()->Void) {
^
B,Cでambiguousって言われるのはわかるけどA,Bのとき通っちゃうのきもちわるい?
*/
func anyFunction(message:String, completion:()->Void) {
println("this is A")
}
func anyFunction(message:String, extra:String? = nil, completion:()->Void) {
println("this is B")
}
func anyFunction(message:String, extra:String? = nil, moreExtra:String? = nil, completion:()->Void) {
println("this is C")
}
anyFunction("fuga") {
_ in
println("hoge")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment