Reputation: 1961
I am making an app calling methods after one second.
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(loadNews)
userInfo:nil
repeats:NO];
how to call thi
Upvotes: 1
Views: 5872
Reputation: 9124
Your question is incomplete. However using the title, I can say that you cannot set the NSTimer to anything like nano-seconds and expect the request be honored in the way you hope.
The smallest interval that it appears it can be set to is 0.1 milliseconds (or 0.0001 seconds). The the api documentation states:
The number of seconds between firings of the timer. If interval is less than or equal to 0.0, this method chooses the nonnegative value of 0.1 milliseconds instead.
Which implies but does not definitely define the smallest value to be 0.1ms.
You should note that like with many computer operating system timers - this is a minimum time not a maximum - there is no guarantee that it will not go for longer if the system is busy doing something else. iOS like Windows or MacOS or Linux is not a 'real time operating system' designed where timelines of events is paramount to the success of the application.
Trying to set a timer to 1 nano second level, or 0.000000001 seconds is just not going to work.
Upvotes: 19
Reputation: 25
U cant do it, but the smallest interval is 0.035
timer = [NSTimer scheduledTimerWithTimeInterval:0.035f
target:self
selector:@selector(loadNews)
userInfo:nil
repeats:NO];;
Upvotes: 0
Reputation: 36752
NSTimeInterval
is measured in seconds. So one nanosecond would be:
NSTimeInterval ti = 0.000000001;
But NSTimer
is not even close to that precision.
Upvotes: 2