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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:17:05+00:00 2026-06-02T05:17:05+00:00

application design/architecture question for a project that I am building. I have a main

  • 0

application design/architecture question for a project that I am building.

I have a main controller which holds an NSMutableArray of currently “active” objects.
Each one of those objects, when instantiated, will have their own NSTimer that is timing the amount of seconds / minutes / hours that the object is in an “active” state.

Should I be generating and allocating these NSTimers on their own separate thread when a user creates the new object? Or can I have multiple timers like this running on the main thread?

Not that familiar with threading so that is why I’m asking. If each object has it’s own NSTimer allocated then threading isn’t necessary? or…?

  • 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-02T05:17:06+00:00Added an answer on June 2, 2026 at 5:17 am

    I don’t think you need NSTimer for this. NSTimer is used to fire a callback after a set amount of time. If you are trying to track the amount of time since an object has been created, do this:

    Upon making object active:

    object.createdAt = [ NSDate date ] ;
    

    To determine how long the object has been active, do this:

    NSTimeInterval numberOfSecondsSinceCreation = [ [ NSDate date ] timeIntervalSinceDate:object.createdAt ] ;
    

    pausable implementation

    I wrote a category you can add to your project that you can use to track ‘active time’ for objects.

    @interface NSObject (Timeable)
    @property ( nonatomic ) NSTimeInterval totalActiveTime ;
    @property ( nonatomic, retain ) NSDate * lastStartTime ;
    @end
    
    @implementation NSObject (Timeable)
    
    -(void)startTimer
    {
        self.lastStartTime = [ NSDate date ] ;
    }
    
    -(void)pauseTimer
    {
        self.totalActiveTime = self.totalActiveTime + [[ NSDate date ] timeIntervalSinceDate:self.lastStartTime ] ;
    }
    
    -(NSDate*)lastStartTime
    {
        return objc_getAssociatedObject( self, @"lastStartTime" ) ;
    }
    
    -(void)setLastStartTime:(NSDate*)date
    {
        return objc_setAssociatedObject( self, @"lastStartTime", date, OBJC_ASSOCIATION_RETAIN_NONATOMIC ) ;
    }
    
    -(NSTimeInterval)totalActiveTime
    {
        NSNumber * number = objc_getAssociatedObject( self, @"totalActiveTime" ) ;
        return  number ? [ number doubleValue ] : 0.0 ;
    }
    
    -(void)setTotalActiveTime:(NSTimeInterval)time
    {
        objc_setAssociatedObject( self, @"totalActiveTime", [ NSNumber numberWithDouble:time ], OBJC_ASSOCIATION_RETAIN_NONATOMIC ) ;
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have gwt-project that is comunication to database. Application design mvp pattern and view
i have a question that is more design and architecture related. I am coming
I have a question regarding the Phonegap basic architecture design: 1.The phonegap project contains
We are currently building architecture for thin-client bookkeeping application. It should follow two main
I am currently developing an application which by design has a three-tier architecture. It
In the book of application architecture design, which I'am reading, I've found the following
Broad design/architecture question. If you have nested components in a GUI, what's the most
I understand that dynamic/static polymorphism depends on the application design and requirements. However, is
I'm looking to design an application that will require some deep control over IP
I am starting to design an application which primarily does XML transformation from one

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.