Formatting Number Literals
Two Swift conventions allow you to enhance number legibility, or how clearly numbers in your code can be read, understood, and checked for correctness. Swift enables you to introduce both underscore separators and leading zeros. This formatting enhances legibility by reducing the cognitive load involved in inspecting numbers. Consistent formatting chunks long numbers into more manageable visual components. Adopting these simple visual flourishes offers a significant legibility win. They don’t interfere with the compilation or execution of your code. At the same time, they present numbers in a more human-consumable fashion.
Adding Underscores
Swift ignores single underscores placed within number literals. Adding underscores ...
Get Swift Style now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.