Clicky

iOS Dev Nugget 306 Underscores in Numeric Literals

.

Need to run a code review on your codebase? Hire me

Did you know that you can include underscores (_) and leading zeros (0) in numeric literals for clarity?

i.e.

print(001) //1
print(1_000_000) //1000000
print(1.234_567) //1.234567

Works with numbers written in base-2 and base-10 too:

print(0b1000_0001) //129
print(0xCC_CC_CC) //Grayish, If you encode RGB in 3 bytes

Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues