I am sure there is no way to determine if two closures are equal.
, . . ( , , . , . , .)
, === , , , Playground.
Playground execution failed: error: MyPlayground.playground:1:20: error: cannot check reference equality of functions; operands here have types '(Int) -> ()' and '(Int) -> ()'
let bar = closure1 === closure2
~~~~~~~~ ^ ~~~~~~~~
, , , , , . - , , , . , , , , .
, , .
func giveMeClosure(aString: String) -> () -> String
{
return { "returning " + aString }
}
let closure1 = giveMeClosure(aString: "foo")
let closure2 = giveMeClosure(aString: "bar")
closure1 closure2 ?
print(closure1()) // prints "returning foo"
print(closure2()) // prints "returning bar"
, . , , , ,
func giveMeACount(aString: String) -> () -> Int
{
return { aString.characters.count }
}
let closure3 = giveMeACount(aString: "foo")
let closure4 = giveMeACount(aString: "bar")
print(closure3())
print(closure4())
-, . - , , Apple . , , .