Last active
April 23, 2016 03:00
-
-
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?
This file contains 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
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