Michael Long
Aug 8, 2022

--

If you take that view then you can never create a meaningful subview just because I might want to change one of the subview's parameters.

One solution, however, is to simply add a default color attribute to the view.

var color: Color = .secondary

Don't pass it and you get the default color. Choose to pass something else and you can override the default color.

Another solution might be to create a secondaryColor attribute in the environment. defaulted to .secondary, but again allowing you to change it before you display the subview.

Or you can subview the thing again, and make a ColoredFootnoteView that's wrapped by FootnoteView.

There are a lot of solutions out there.

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

No responses yet