classSwizzle:nsobject {Override classfunc Load () {uibutton.xxx_swizzlesendaction ()}}extension UIButton {classfunc xxx_swizzlesendaction () {structXxx_swizzletoken {Staticvar oncetoken:dispatch_once_t =0} dispatch_once (&xxx_swizzletoken.oncetoken, {(), VoidinchLet cls:anyclass! =uibutton.self let Originalselector= Selector ("sendAction:to:forEvent:") Let Swizzledselector= Selector ("xxx_sendAction:to:forEvent:") Let Originalmethod=Class_getinstancemethod (CLS, originalselector) let Swizzledmethod=Class_getinstancemethod (CLS, swizzledselector) method_exchangeimplementations (Originalmethod, SwizzledMeth OD)})} PublicFunc xxx_sendaction (Action:selector, to:anyobject!, forevent:uievent!) { structXxx_buttontapcount {Staticvar count:int =0} xxx_buttontapcount.count+=1println (Xxx_buttontapcount.count) Xxx_sendaction (action, to:to, Forevent:forevent)}}
The number of clicks of all buttons in the Swift statistics project