NSTimeInterval
is a double
, thus it cannot take a nil
, and 0 represents something that should happen immediately. Is there a constant that means "never"... or an astronomically huge value, or should I use -1?
Asked
Active
Viewed 1,039 times
3

devios1
- 36,899
- 45
- 162
- 260
-
4`double` can take `inf` values. You can test with `isinf(x)` or `(x > DBL_MAX)`. – s.bandara Jan 28 '15 at 19:16
2 Answers
2
As suggested by s.bandara, use a very large number to treat a time interval as "infinite" or "never".
DBL_MAX
is the largest value a double can hold. This macro is declared in float.h
:
#define DBL_MAX (9.999999999999999e999)

JAL
- 41,701
- 23
- 172
- 300
-
-
DBL_MAX is as close to infinity as a double value can get. I've made this answer a community wiki based on the comment on the question. You are free to edit it to improve the answer. – JAL Nov 19 '15 at 04:50
-
No, it's not, there's a special value in IEEE 754 floating point to represent infinity. I can't really see how to edit this without rewriting it completely. – jscs Nov 19 '15 at 05:04
-
So feel free to write your own answer if you feel that this answer is deficient. – JAL Nov 19 '15 at 12:28
1
In Swift, use TimeInterval.infinity
. For example, in SwiftUI to conditionally enable a timeline view to update every second or never, use:
TimelineView(.periodic(from: start, by: isRunning ? 1 : .infinity))

Edward Brey
- 40,302
- 20
- 199
- 253