Passing arguments to selector in Swift

It looks like you’re misunderstanding a couple of things. When using target/action, the function signature has to have a certain form… func doSomething() or func doSomething(sender: Any) or func doSomething(sender: Any, forEvent event: UIEvent) where… The sender parameter is the control object sending the action message. In your case, the sender is the UITapGestureRecognizer Also, … Read more

Swift access control with target selectors

you need @objc to expose a private method to objc runtime @objc private func buttonDidTap(button:UIButton!) { println(button.char) } From Xcode6 beta4 release notes Declarations marked private are not exposed to the Objective-C runtime if not otherwise annotated. IB outlets, IB actions, and Core Data managed properties remain exposed to Objective-C whatever their access level. If … Read more

List selectors for Objective-C object

This is a solution based on the runtime C functions: class_copyMethodList returns a list of class methods given a Class object obtainable from an object. #import <objc/runtime.h> [..] SomeClass * t = [[SomeClass alloc] init]; int i=0; unsigned int mc = 0; Method * mlist = class_copyMethodList(object_getClass(t), &mc); NSLog(@”%d methods”, mc); for(i=0;i<mc;i++) NSLog(@”Method no #%d: … Read more

Objective-C: How to call performSelector with a BOOL typed parameter?

In the case that you cannot alter the target-method signature to accept a NSNumber in place of a BOOL you can use NSInvocation instead of performSelector: MyTargetClass* myTargetObject; BOOL myBoolValue = YES; // or NO NSMethodSignature* signature = [[myTargetObject class] instanceMethodSignatureForSelector: @selector( myMethodTakingBool: )]; NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: signature]; [invocation setTarget: myTargetObject]; [invocation setSelector: … Read more

Selector in swift3

Selector(“tap:”) should now be written as #selector(tap(gestureReconizer:)) Also, you should declare tap as func tap(_ gestureRecognizer: UITapGestureRecognizer) as per the new Swift API Guidelines in which case your selector would then become #selector(tap(_:)).

Passing parameters on button action:@selector

Edit. Found a neater way! One argument that the button can receive is (id)sender. This means you can create a new button, inheriting from UIButton, that allows you to store the other intended arguments. Hopefully these two snippets illustrate what to do. myOwnbutton.argOne = someValue [myOwnbutton addTarget:self action:@selector(buttonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside]; and – (IBAction) buttonTouchUpInside:(id)sender { MyOwnButton … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)