2

I'm in an odd state where it would help me a lot if I could compare 2 closures to see if they are the same reference object. I tried this:

let closure1 = { (a:String) in print(a)}
let closure2 = closure1

if closure1 as AnyObject === closure2 as AnyObject {
    print("success")
}

This doesn't work, I know it seems silly, but being able to do this comparison will simplify something I'm working on. Did I miss something, I have done reference comparisons like this in the past in swift, is there something about closures that makes this not valid? Is there another way to do something like this?

Kevin DiTraglia
  • 25,746
  • 19
  • 92
  • 138
  • 1
    You can't https://stackoverflow.com/questions/24111984/how-do-you-test-functions-and-closures-for-equality – NSAdi Jan 29 '18 at 00:47
  • Yes, still cant in 2021 to do such trivial thing in swift (blessed javascript) – mikep Feb 26 '21 at 12:36

0 Answers0