If you look closely at what the navigationBarTitle
call resolves to, it isn’t the method you linked:
func navigationBarTitle(_ title: Text, displayMode: NavigationBarItem.TitleDisplayMode) -> some View
It is:
func navigationBarTitle<S>(_ title: S, displayMode: NavigationBarItem.TitleDisplayMode) -> some View where S : StringProtocol
It can’t resolve to the first one because you are not passing a Text
as the title, are you? You declared the argument title
to be a String
.
Here’s the documentation for the second method. From the documentation we can clearly see that it is available from iOS 14.0 to 14.2.
The reason why using a string literal as the title works (such as in ContentView
) is because you are calling yet another overload of navigationBarTitle
:
func navigationBarTitle(_ titleKey: LocalizedStringKey, displayMode: NavigationBarItem.TitleDisplayMode) -> some View
LocalizedStringKey
conforms to ExpressibleByStringLiteral
, so string literals can be passed to an argument of type LocalizedStringKey
, but not a variable like title
.
CLICK HERE to find out more related problems solutions.