Xcode 12.5, Failed to build content in preview

In tutorial IOS & Swift UI for Beginners, when adding Slider this message comes up. Build successful, Simulator ok just preview stops and slider does not appear in preview.
initializer ‘init(value:in:onEditingChanged:)’ requires that ‘Int’ conform to ‘BinaryFloatingPoint’

In Xcode 12.4 I did not have this problem.

hi Corneilus! that’s very interesting. Xcode 12 has been surprisingly relaxed about constant numbers, accepting CGFloat values without the decimal point. 12.5 still accepts padding(1) instead of requiring padding(1.0).

Assuming this is the line you added, just add .0 to 50:

Slider(value: .constant(50.0), in: 1.0...100.0)

That worked, thank you very much.
The error started at the instant I dragged the slider onto the preview screen before I typed .constant. So, I hope that helps.

Ah, that sounds like an Xcode bug. Still, doesn’t hurt to get into the habit of using the right type of number. I was starting to get a bit lazy.

update: I tried adding a Slider and yes, Xcode 12.5 is a bit trigger-happy. When it’s like that, just ignore the error messages until you’ve finished adding code.

This topic was automatically closed after 166 days. New replies are no longer allowed.