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

后端 未结 11 1809
深忆病人
深忆病人 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:33

    You can use ActionClosurable which support UIControl, UIButton, UIRefreshControl, UIGestureRecognizer and UIBarButtonItem. https://github.com/takasek/ActionClosurable

    Bellow show example of UIBarButtonItem

    // UIBarButtonItem
    let barButtonItem = UIBarButtonItem(title: "title", style: .plain) { _ in
        print("barButtonItem title")
    }
    

提交回复
热议问题