Adding days to a date using the result of a division operation

var testTwo: Double = 0
testDouble = 80
testTwo = 200
var testThree: Int = 0
testThree = Int(testTwo/testDouble)
var testDate: Date = .now
var  dateComponent = DateComponents()
dateComponent.day = testThree
var newDate: Date = Calendar.current.date(byAdding: dateComponentwith a thread error , to: testDate)!

This code works in a playground. However, when I try to use it in Xcode for my app it fails with the following error: Thread 1: Fatal error: Double value cannot be converted to Int because it is either infinite or NaN I printed the value being converted to Int and it was not NAN or infinite.

Where does 'testDouble' come from? And what's testDouble's type?

What version of Xcode are you using? What version of iOS/macOS/other OS are you building for?

I tried it in Xcode 26.1.1 on macOS 15.7.2, targeting iOS 26.1 and it works fine, no errors.

Here's a reduced version (that also works):

var dateComponent = DateComponents()
dateComponent.day = Int(200 / 80)
let newDate: Date = Calendar.current.date(byAdding: dateComponent, to: Date.now)!
print(newDate)
Adding days to a date using the result of a division operation
 
 
Q