Visual separator "Underscore"
In Swift, underscores can be used as a visual separator in numeric literals to improve readability. This feature was introduced in Swift 3 and is available in all subsequent versions of the language.
For example, consider the following integer literals:
let a = 1000000
let b = 1_000_000
Both a and b have the same value of 1000000, but b uses underscores as separators to make the number easier to read. This can be particularly useful for large numbers that may be difficult to parse at a glance.
Comments
Post a Comment