Group Group Group Group Group Group Group Group Group

Chapter 3: swiftUI error message at deceptive location

A general warning that swiftUI error messages may be at very deceptive locations.

In the first code sample below I left the “l” off of “.padding(.horizontal)” at the end of my ColorSlider VStack. That resulted in a “boolean context” error message 10 lines above!

Second code sample shows that the corrected “horizontal” fixes the boolean context error 10 lines above.

Hopefully Xcode will handle this better in the future.

hi Darrell! yes, it seems what I wrote back in June is still all too true:

unhelpful error messages, including Unable to infer complex closure return type; add explicit type to disambiguate , ‘(LocalizedStringKey) -> Text’ is not convertible to ‘(LocalizedStringKey, String?, Bundle?, StaticString?) -> Text’ and Function declares an opaque return type, but has no return statements in its body from which to infer an underlying type , which basically meant “huh??”. And these messages seldom appeared near code that I had just added. If you see messages that don’t seem helpful, or point at code that was perfectly fine before, try commenting out what you just added. Also check your spelling and ensure that your braces and parentheses match. Finally, restarting Xcode is always a good idea …! ;]

Another tip: if the preview says the app is crashing, and suggests you look at the crash log, it’s worth having a look. Problems can appear there that don’t show up in build or runtime errors.

1 Like