Search code examples
swiftxcodeswiftuiswift5xcode11

Xcode Inconsistent Compiler Errors


When I use a VStack as such:

VStack(alignment: .leading) {
  ...
}

my code usually builds. But sometimes I change something else in the code, and Xcode gives me Static member 'leading' cannot be used on instance of type 'HorizontalAlignment'. I have to mess around with my code until it eventually lets me build using the exact same code with which it gave that error.

Does anyone know why this is happening and what I could do to fix this?


Solution

  • It's happening because the compiler's error diagnostic routine for SwiftUI expressions is not very good, so its way of telling you that you've made a syntactical mistake doesn't pinpoint the actual mistake. Things should be improved in Xcode 11.4, according to the release notes. For more information about what's going on under the hood, see https://swift.org/blog/new-diagnostic-arch-overview/.