Vipera74
Vipera74

Reputation: 227

Infinite UIStepper in Swift

Is it possible to set an infinite maximum value on a UIStepper? If not, is there an alternative to not having limits in counting?

Upvotes: 0

Views: 925

Answers (1)

Duncan C
Duncan C

Reputation: 131436

A UIStepper uses a Double for its maximumValue property. Set it to Double.greatestFiniteMagnitude.

Double.greatestFiniteMagnitude isn't infinite, but it's really freaking huge. (≈1.80e+308).

EDIT

Actually, it looks like you can say

stepper.maximumValue = Double.infinity

That appears to work.

Note that if your step value isn't very large, when your value gets large enough that it requires scientific notation to display, you're going to have a tough time showing changes in value. Plus, at very large magnitudes, floating point numbers lose precision. Increasing a very large double by a value of 1 might not change its value.

EDIT #2:

I just tried it, and if you set

stepper.maximumValue = Double.greatestFiniteMagnitude

and

stepper.value = Double.greatestFiniteMagnitude / 2

Then in theory, when you tap the + on the stepper (with a default stepValue of 1) then the value should change. However, at a value of Double.greatestFiniteMagnitude/2, a change in value of 1 is too small to change the mantissa of the value at all. At the default stepValue of 1, when the stepper.value is Double.greatestFiniteMagnitude / 2, tapping the stepper does not cause any change in the stepper's value.

Upvotes: 5

Related Questions