Can I make #selector refer to a closure in Swift?

后端 未结 11 1805
深忆病人
深忆病人 2020-12-09 15:12

I want to make a selector argument of my method refer to a closure property, both of them exist in the same scope. For example,

func backgroundC         


        
11条回答
  •  离开以前
    2020-12-09 15:49

    It is now possible. I've created a gist for block-based selectors in Swift 4.

    https://gist.github.com/cprovatas/98ff940140c8744c4d1f3bcce7ba4543

    Usage:

    UIButton().addTarget(Selector, action: Selector { debugPrint("my code here") }, for: .touchUpInside)`
    

提交回复
热议问题