Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8493049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:54:00+00:00 2026-06-10T22:54:00+00:00

Possible Duplicate: How to make a periodic call to a method in objective c?

  • 0

Possible Duplicate:
How to make a periodic call to a method in objective c?

I am making an app where when the user touches the screen, the following method is called:

- (void)explode:(int)x

The user only has to touch the screen once, but I want the method to be called repeatedly every 0.1 seconds for 100 times, and then it should stop being called.

Is there a way of setting up a ‘temporary’ timer like this on a method where an integer is being passed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:54:02+00:00Added an answer on June 10, 2026 at 10:54 pm

    You could pass a counter and the ‘x’ as into the timer’s userInfo. Try this:

    Create the timer in the method that’s catching the touch event and pass a counter and the int ‘x’ into the userInfo:

    NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] initWithCapacity:2];
    [userInfo setValue:[NSNumber numberWithInt:x] forKey:@"x"];
    [userInfo setValue:[NSNumber numberWithInt:0] forKey:@"counter"];
    
    [NSTimer timerWithTimeInterval:0.1
                            target:self
                          selector:@selector(timerMethod:)
                          userInfo:userInfo
                           repeats:YES];
    

    Create the timer method, check the userInfo’s number count, and invalidate the timer after 100 times:

    - (void)timerMethod:(NSTimer *)timer
    {
        NSMutableDictionary *userInfo = timer.UserInfo;
        int x = [[userInfo valueForKey:@"x"] intValue];
    
        // your code here
    
        int counter = [[userInfo valueForKey:@"counter"] intValue];
        counter++;
    
        if (counter >= 100)
        {
            [timer invalidate];
        }
        else
        {
            [userInfo setValue:[NSNumber numberWithInt:x] forKey:@"x"];
            [userInfo setValue:[NSNumber numberWithInt:counter] forKey:@"counter"];
        }
    
    }
    

    Please also see the Apple docs on NSTimer:

    https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nstimer_Class/Reference/NSTimer.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: how to make phone call by using objective c? I am trying
Possible Duplicate: Make iPhone app paid version replace free version on install from app
Possible Duplicate: how to make screen screenshot with win32 in c++? I am currently
Possible Duplicate: How to make half curl animation in iPhone like the maps app
Possible Duplicate: How to make a phone call in android and come back to
Possible Duplicate: How to create a windows service from java app How to make
Possible Duplicate: How to make in Javascript full screen windows (stretching all over the
Possible Duplicate: how to make phone call using intent in android? Please give me
Possible Duplicate: Can you make an Extension Method Static/Shared? Extension methods are great! Pardon
Possible Duplicate: Make error: missing separator I am so stressed out by this silly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.