0

Swift 5.0 normally cast NSValue to CMTimeRange type, it does not supported in swift 5.3? For example this worked correctly in Xcode 11.7 (Swift 5.0)

let nsValue = NSValue(timeRange: CMTimeRange(start: CMTime(seconds: 12, preferredTimescale: 1), duration: CMTime(seconds: 22, preferredTimescale: 1)))
let value = nsValue as? CMTimeRange

But fails in Xcode 12 (Swift 5&) and show warning:

Cast from 'NSValue' to unrelated type 'CMTimeRange' always fails
Tayphoon
  • 71
  • 9

2 Answers2

1

NSValue has timeRangeValue which returns CMTimeRange without explicit cast.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Digitech
  • 262
  • 2
  • 9
  • Yes, but it may return empty struct. Common types can be cast to it's real type without access to property. My question is why it missed for this property? – Tayphoon Sep 28 '20 at 07:52
0

dharmon is correct:

iOS13: let value = nsValue as? CMTimeRange

iOS14: let value = nsValue.timeRangeValue