Discover Number Separators


You’re more of a video kind of person? I’ve got you covered! Here’s a video with the same content than this article 🍿


I'm going to show you a pretty cool trick to make large numbers much easier to read!

You've probably noticed that when you write numerical constants that start to have more than 4 or 5 digits, then these numbers become much harder to read at a glance.

Fortunately, Swift comes with a built-in solution for this!

Anywhere inside a number literal, you're allowed to add underscores to help better separate the digits.

So here we can use these separators to group the digits by thousands...

...and immediately we can notice that the numbers have become much easier to read!

That’s all for this article, I hope you’ve enjoyed it!

Here’s the code if you want to experiment with it:

let bigNumber = 123_456_789
Previous
Previous

Apple made it easy to keep track with all the WWDC additions 🍎

Next
Next

Here are 5 great articles to keep up with WWDC 😌