Skip to content

Instantly share code, notes, and snippets.

@bagelturf
Last active April 23, 2016 03:00
Show Gist options
  • Save bagelturf/85dab3297557e1b237507460acb0ffba to your computer and use it in GitHub Desktop.
Save bagelturf/85dab3297557e1b237507460acb0ffba to your computer and use it in GitHub Desktop.
Why do I get error: cannot convert value of type 'Int' to expected argument type 'XX' on line 10?
class XX {
func a(b: Int) -> Int {
return b
}
var functionA = a
func run() {
print("\(functionA(1))") // Needs (self) after functionA
}
}
var x = XX()
x.run()
// What I really need is as below
// Default is nil
class P {
var a: (()->())!
func run() {
if let f = a {
f()
}
}
}
var p = P()
p.run()
p.a = { print("PP") }
p.run()
// Default is empty closure
class Q {
var a = { ()->() in }
func run() {
a()
}
}
var q = Q()
q.run()
q.a = { print("QQ") }
q.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment