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 9019049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:40:59+00:00 2026-06-16T04:40:59+00:00

I want to have an NSTimer that would fire a selector every x seconds

  • 0

I want to have an NSTimer that would fire a selector every x seconds if a certain condition (the selector is NO) is true.
The value of x should change like this – 10, 20, 40, 60, 120.

If the selector changes to YES (it returns a BOOL) the timer should stop and change it’s initial time to 10 seconds.

I’ve got this code for a timer:

double i;
for (i= 10.0; i < maxInternetCheckTime; i++) {
    [NSTimer scheduledTimerWithTimeInterval:i
                                     target:self
                                   selector:@selector(checkForInternetConnection)
                                   userInfo:nil
                                    repeats:NO];
    NSLog(@"Timer is %f seconds", i);
}

But the output I get is just not what I intended to see in the beginning:

2012-12-21 19:25:48.351 Custom Queue[3157:c07] Timer is 10.000000 seconds
2012-12-21 19:25:48.352 Custom Queue[3157:c07] Timer is 11.000000 seconds
2012-12-21 19:25:48.352 Custom Queue[3157:c07] Timer is 12.000000 seconds
2012-12-21 19:25:48.352 Custom Queue[3157:c07] Timer is 13.000000 seconds
2012-12-21 19:25:48.352 Custom Queue[3157:c07] Timer is 14.000000 seconds
2012-12-21 19:25:48.352 Custom Queue[3157:c07] Timer is 15.000000 seconds

And so on.
What am I doing wrong in this pretty trivial task?

  • 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-16T04:41:00+00:00Added an answer on June 16, 2026 at 4:41 am
          for (i= 10.0; i < maxInternetCheckTime; i++) {
             [NSTimer scheduledTimerWithTimeInterval:i
    

    You are scheduling a set of 10 timers at the same moment to be executed after: 10, 11, 12,13, etc seconds.

    You need just one timer to start with:

    [NSTimer scheduledTimerWithTimeInterval:10
                                     target:self
                                   selector:@selector(checkForInternetConnection:)
                                   userInfo:nil
                                    repeats:NO];
    

    then in checkForInternetConnection you schedule a new one if needed:

    -(void)checkForInternetConnection:(NSTimer*)firedTimer {
    
       float interval = firedTimer.timeInterval;
       interval *= 2;
    
       if (<CONDITION>) {
         [NSTimer scheduledTimerWithTimeInterval:interval 
                                     target:self
                                   selector:@selector(checkForInternetConnection)
                                   userInfo:nil
                                    repeats:NO];
       }
     }
    

    I hope the logic is clear:

    1. you schedule a check;

    2. you do the check;

    3. if check is not ok, you schedule a new one.

    Hope it helps.

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

Sidebar

Related Questions

I have a NSTimer that fires with an interval of 3 seconds to decrease
I want to have an insert tab button for my UITextView so that users
I have an NSTimer that runs at 60hz. With an OpenGL scene loaded and
I have a timer that I use to check a web address every 11
Have a question... I have Timer [NSTimer scheduledTimerWithTimeInterval:120 target:self selector:@selector(action1:) userInfo:nil repeats:YES]; But when
I have a timer that launches in viewDidLoad that looks like this [NSTimer scheduledTimerWithTimeInterval:0.001f
I have a UITableView that I want updated by a method called by a
I have a application that periodically (via an NSTimer ) asks for the users
I have an image that i want to display as a sun during daytime
I have an app that needs to send collected data every X milliseconds (and

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.