• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Keeping NSTimeInterval updated with current time
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Keeping NSTimeInterval updated with current time


  • Subject: Re: Keeping NSTimeInterval updated with current time
  • From: Graham Cox <email@hidden>
  • Date: Tue, 3 Nov 2009 12:10:28 +1100


On 03/11/2009, at 10:10 AM, PCWiz wrote:

What I want to do is around every 5 minutes, update the timeInterval to be consistent with the current time. The problem is that I need to do this update for a large number of instances of the object. One way I could think to do this would be to enumerate through the array containing the objects every 5 minutes and just set the timeInterval property. But is there a more efficient way to do this?


The simple answer is to use NSArray's - makeObjectsPerformSelector:withObject: to rapidly pass a parameter to the same method of a collection of objects.

But, maybe a better answer is to consider why you are doing this. If you have a bunch of objects that need to know the current time (to the nearest five minutes) why not just have them grab that time at the moment when they need to know it. If they are just sitting there they don't need to be updated - only when one of them is called into play and needs to do some calculation with the time does that time need to be updated, at which point it should grab it for itself. If rounding off the time to the last 5-minute interval is a problem (e.g. every object must have the exact same value), you could do that every 5 minutes and cache the result somewhere where all the other objects can grab it as needed.

This type of lazy evaluation is by far the better way to code a problem like this - do the minimum work necessary, and never push state to objects that don't need it *NOW*.

--Graham


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Keeping NSTimeInterval updated with current time
      • From: Ken Thomases <email@hidden>
References: 
 >Keeping NSTimeInterval updated with current time (From: PCWiz <email@hidden>)

  • Prev by Date: Re: pointer to structure member reference?
  • Next by Date: Re: pointer to structure member reference?
  • Previous by thread: Re: Keeping NSTimeInterval updated with current time
  • Next by thread: Re: Keeping NSTimeInterval updated with current time
  • Index(es):
    • Date
    • Thread