1
votes

I have a method like this :

-(void)fastTapCartBack:(NSString*)ActionType

And I want to use it as selector in NSTimer like this :

self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:[self performSelector:@selector(fastTapCartBack:) withObject:@"FAST"] userInfo:nil repeats:NO]

But It have Error :

Implicit conversion of an Objective-C pointer to 'SEL _Nonnull' is disallowed with ARC

2

2 Answers

1
votes

You cannot pass a second parameter in the target / action pattern.

However in case of NSTimer there is a very suitable solution, the userInfo parameter

self.timer = [NSTimer scheduledTimerWithTimeInterval:1 
                                              target:self 
                                            selector:@selector(fastTapCartBack:)
                                            userInfo:@"FAST" 
                                             repeats:NO];

and get the information in the selector method

-(void)fastTapCartBack:(NSTimer *)timer {
     NSString *info = (NSString *)timer.userInfo;
}
1
votes

You are passing a method call [self performSelector:@selector(fastTapCartBack:) withObject:@"FAST"] as selector, this is not allowed by Objective-C

replace this

self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:[self performSelector:@selector(fastTapCartBack:) withObject:@"FAST"] userInfo:nil repeats:NO];

By this

You should use NSInvocation way

NSMethodSignature * signature = [ViewController instanceMethodSignatureForSelector:@selector(fastTapCartBack:)];
NSInvocation * invocation = [NSInvocation
             invocationWithMethodSignature:signature];
[invocation setTarget:self];
[invocation setSelector:@selector(fastTapCartBack:)];
NSString * argument = @"FAST";
[invocation setArgument:&argument atIndex:2];

self.timer2 = [NSTimer scheduledTimerWithTimeInterval:1 invocation:invocation repeats:NO];