Moved to https://github.com/mithyer/Ralyo/tree/master/src/Extension/Selector-Closure
Selector-Closure is a light way to convert objc target-action selector to closure style
Type of Object calling "sce" will be auto recognized in closure
use ".sce" to make closure callback
let btn = UIButton()
let field = UITextField()
// for specific event
_ = btn.sce.add(.touchUpInside) { sender in
// ... sender is UIButton
}
// for default event(UIButton, UISwitch, UISlider, UITextField has default events)
let invoker = field.sce.add { sender in
// ... sender is UITextField
}
// now you can remove action with invoker returned
field.sce.remove(invoker)
// remove all for events
field.sce.removeAll(.touchUpInside) { sender in
// ...
}
// test didAdd events
let res: Bool = field.sce.didAdd(.touchUpInside)
use ".SCE" to initialize
let item = UIBarButtonItem.SCE.initialize(title: "test", style: .plain, { item in
// ...
})
// ...
use ".SCE" to initialize
// init a recognizer,
let tgr = UITapGestureRecognizer.SCE.initialize { tgr in
// tgr is UITapGestureRecognizer
}
let sgr = UISwipeGestureRecognizer.SCE.initialize { sgr in
// sgr is UISwipeGestureRecognizer
}
use ".sce" to make closure callback
// fast make tap action
let view = UIView()
let tapGestureRecognizer = view.sce.whenTapped { tgr in
// tgr === tapGestureRecognizer
}
// you have an instance named obj
let invoker = Invoker(obj) { obj in
// ...
}
let act = invoker.action // convert done, now pass invoker to target, act to action