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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:19:36+00:00 2026-05-27T20:19:36+00:00

I want a timer class that can post messages to a delegate when there

  • 0

I want a timer class that can post messages to a delegate when there are 1/2/3 seconds to go.

My test target consistently crashes.

  • iOS logic unit test target.
  • Tests class that times a duration using a repeating NSTimer
  • One test with no asserts. The test passes, but then the target crashes with:

/Developer/Tools/RunPlatformUnitTests.include: line 415: 770 Bus error "${THIN_TEST_RIG}" "${OTHER_TEST_FLAGS}" "${TEST_BUNDLE_PATH}"

It seems to me that it’s some kind of memory allocation error, but I can’t figure out what I’m missing. The problem is associated with the stop timer routine somehow. It’s only when the timer runs out that the target crashes.

Things I’ve tried

  • Build and Analyze – no errors reported
  • Remove -framework and UIKit from the linker flags
  • Removing dealloc – this has no effect

Test Code

-(void)testGivenThreeSecondDurationAtOneSecondDelegateShouldBeToldToShowGreenCard {
    JGTimerController *timer = [JGTimerController timerWithDurationValue:1 delegate:nil];
    [timer startTimer];

    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.1]];
}

Class Code

@interface JGTimerController : NSObject {
    NSNumber    *duration;
    NSTimer     *timer;
    id <NSObject, JGTimerControllerDelegate> _delegate;
}
@property (nonatomic, retain) NSNumber *duration;
... public methods...
@end


@implementation JGTimerController

@synthesize duration;

+(JGTimerController *)timerWithDurationValue:(NSUInteger)durationValue delegate:(id <JGTimerControllerDelegate>)delegate_ {
    JGTimerController *instance = [[[JGTimerController alloc] initWithDurationValue:durationValue delegate:delegate_] autorelease];
    return instance;
}

-(JGTimerController *)initWithDurationValue:(NSUInteger)durationValue delegate:(id <JGTimerControllerDelegate>)delegate_ {
    self = [super init];
    timer = nil;
    [self setDurationValue:durationValue];
    _delegate = delegate_;
    return self;
}

-(NSUInteger)durationValue {
    NSNumber *result = [self duration];
    return result ? [result intValue] : 0;
}

-(void)setDurationValue:(NSUInteger)value_ {
    [self setDuration:[NSNumber numberWithInt:value_]];
}

-(BOOL)stopTimerAtZeroDuration:(NSTimer *)timer_ {
    if ([self durationValue] == 0) {
        [self stopTimer];
        return YES;
    }
    return NO;
}

-(void)startTimer {
    if ([self stopTimerAtZeroDuration:nil])
        return;

    timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerDidCountDownByASecond:) userInfo:nil repeats:YES];
}

-(void)stopTimer {
    if ([self durationValue] == 0 && [_delegate conformsToProtocol:@protocol(JGTimerControllerDelegate)])
        [_delegate showRedCard];

    [timer invalidate];
    [timer release];
}

-(BOOL)timerIsRunning {
    return (timer != nil);
}

-(void)timerDidCountDownByASecond:(NSTimer *)timer_ {
    [self setDurationValue:[self durationValue] - 1];
    [self stopTimerAtZeroDuration:timer_];
}

-(void)dealloc {
    [_delegate release];
    [timer release];
    [duration release];
    [super dealloc];
}

@end
  • 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-05-27T20:19:37+00:00Added an answer on May 27, 2026 at 8:19 pm

    Likewise, timer should not be released. NSTimer is like every other NSObject, if you did not alloc, copy or retain, you do not need to release.

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

Sidebar

Related Questions

I want to create a class that initializes a timer which will be used
I have an extended dialog class that I want to show for 3 seconds
There are times that I have a code snippet that I want to post
How can I use variables to set my timer? I want to control delay
I've managed to make a typewriter class that does what I want it to
I am having a slight problem. I want a django app that can upload
I want to discover at run-time ONLY the static Methods of a class, how
I want to use a timer in my simple .NET application written in C#.
I want to create an incrementing second timer like a stopwatch. So I want
I want to pass a number value to a Timer. How do I do

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.