The Perfect Pie Chart using SwiftUI 2.0
Part 7 of the chart series
When I wrote the first piece on drawing a pie in SwiftUI 2.0 my intention was to keep it brief. The bar chart series had taken three articles, and I wanted to jump to the solution quicker. But I wrong — drawing pies has come with a quagmire of conflicts. It certainly wasn’t a piece of pie. And here we are on version 4. What worked and what didn’t and is this really the final countdown.
Quagmire of Conflicts
The Pie V1
Version 1 was well received, my editor thought it was awesome, and he is a good judge :) but no in brutal honestly there was some room for improvement. I focused within it on drawing pie pieces and used an observedObject to store data/make changes. It worked well, but I wasn’t happy with the end result since it quivered a little too much for comfort— I thought I could do better.
The Pie V2
In Version 2 of the pie I dropped the observedObject. The problem was that I needed to update multiple pieces, before doing a view update. A requirement that wasn’t going to work with a published variable. In this version I introduced a second struct to hold the colouring scheme and used it to animate drawing the pieces piece by piece. I also took change of the refreshing of the…