Swift 3:fatal error: Double value cannot be converted to Int because it is either infinite or NaN

前端 未结 2 1503
猫巷女王i
猫巷女王i 2021-01-17 16:54

When I call this method, an error received. How to handle NaN or infinite value during assign to hour, min or sec?

Here is my code:

private func se         


        
2条回答
  •  半阙折子戏
    2021-01-17 17:27

    You should check if totalSeconds is a valid value, like:

    guard !(totalsSeconds.isNaN || totalSeconds.isInfinite) else {
        return "illegal value" // or do some error handling
    }
    

    And check this: Convert Float to Int in Swift

提交回复
热议问题