user1876553
user1876553

Reputation: 113

Calling a method with arguments after certain time

I want to call a method after certain time. This is just an example.

 - (void)myMethod:(int)value1 setValue2:(CGPoint)value2{

 //Do Something with values


}

At first I thought

   [self scheduleOnce:@selector(myMethod:setValue2:) delay:timeToWait];

but I can't pass the arguments when using selector, so Im asking you guys for an alternative...What could I do? Thanks for your time guys and have a great day!

Upvotes: 1

Views: 407

Answers (2)

SeanT
SeanT

Reputation: 1791

You could put your arguments into an NSDictionary and pass that as the object parameter to - (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay

Upvotes: 1

yeesterbunny
yeesterbunny

Reputation: 1847

You can try GCD's dispatch_after. For instance:

    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [self myMethod:someValue setValue2: someValue2];
    });

Upvotes: 4

Related Questions