Swift 5.1: Numeric Type Conversion Cheat Sheet

let integerValue = 8
let doubleValue = 8.2
// let sum = integerValue + double
// Error: type mismatch

// Use an opt-in approach that prevents hidden
// conversion errors and helps make type conversion
// intentions explicit
let sum = Double(integerValue) + double
// OK: Both values have the same type

Leave a Reply

Your email address will not be published. Required fields are marked *