Display a Text() with a foreground color based on a condition
There is a shorter and faster way, using ternary operators.
You could use
Text(&quot;Home&quot;).foregroundColor(self.viewRouter.currentView == &quot;home&quot; ? Color.blue: Color.black)

instead  of
{ () -&gt; Text in
  if self.viewRouter.currentView == &quot;home&quot; {
    return Text(&quot;Home&quot;).foregroundColor(Color.blue)
  } else {
    return Text(&quot;Home&quot;)
  }
}()

However, with the advent of macOS Mojave 10.14 two years ago, users had an option to enable dark mode. So, unless you've explicitly disabled dark mode in your app, Color.black will blend in with the rest of your app bar. To prevent this, check for dark mode with UserDefaults.standard.object(forKey: &quot;AppleInterfaceStyle&quot;). If the user is using light mode, UserDefaults.standard.object(forKey: &quot;AppleInterfaceStyle&quot;) will be nil, and if it's dark mode, it will be &quot;Dark&quot;
Text(&quot;Home&quot;).foregroundColor(self.viewRouter.currentView == &quot;home&quot; ? Color.blue: UserDefaults.standard.object(forKey: &quot;AppleInterfaceStyle&quot;) == nil ? Color.black: Color.white)


As @BenLeggiero has suggested, this is a much shorter way to do the above:
Text(&quot;Home&quot;).foregroundColor(viewRouter.currentView == &quot;home&quot; ? .blue : .primary)