9

I want to keep a view always at the front. In Swift CGFLOAT_MAX and FLT_MAX are replaced with corresponding .greatestFiniteMagnitude. So, I used:

view.layer.zPosition = .greatestFiniteMagnitude

It works fine, but now I get a warning:

CoreAnimation: zPosition should be within (-FLT_MAX, FLT_MAX) range.

Is there a way to get rid of the warning (maybe a better value to use here)?

Thanks.

timaktimak
  • 1,380
  • 1
  • 12
  • 21

1 Answers1

24

On a 64-bit platform

CGFloat.greatestFiniteMagnitude = Double.greatestFiniteMagnitude = 1.79769313486232e+308
Float.greatestFiniteMagnitude = 3.40282e+38

Apparently the zPosition should be in the (smaller) range of a Float:

view.layer.zPosition = CGFloat(Float.greatestFiniteMagnitude)
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • why not using `CGFloat.greatestFiniteMagnitude` instead of casting to `CGFloat` is there a problem with that – zombie Dec 01 '17 at 10:07
  • 1
    @zombie: That are different values. On a 64-bit platform, CGFloat.greatestFiniteMagnitude = Double.greatestFiniteMagnitude = 1.79769313486232e+308, but Float.greatestFiniteMagnitude = 3.40282e+38. – Martin R Dec 01 '17 at 10:08