I was getting ready for a "What's new in Swift 5" meetup presentation and noodling around with string interpolation. Inspired by Michael Ilseman and Zipper's recent try! Swift talk ( https://youtu.be/lMhGnTFA9CI ), I thought I would post my code to see if you had any feedback for me. Also, a couple of questions below.
I am guessing that I am reinventing some of the fundamentals that will be implemented in future Swift in a much better way.
I wanted to be able to take a number like 6.02e23 and show it in the form 6.02x10^23 (except using unicode superscript numbers). My first version used String(format:) and then split based on the "e". This is considered bad form now, right?
I had some trouble with log10 and BinaryFloatingPoint and the escape hatch I used was converting to a Double(). Any better ideas?
It seems like there should be an easy way to take an array of Characters and join it to a String. I couldn't figure out how to do that so, I just converted to an array of Strings and joined.
I started out with one interpolation but then broke it up into three. One for the scientific notation, one for superscript numbers, and one for enforcing precision. I am loving the interpolation design because it feels very composable. It will be great once we have a bunch of batteries-included, fundamental building in the standard library.
Here is a link to my code:
Thank you. Best wishes,