Xcode shows error on wrong line

I have this code in my SwiftUI view struct


HStack{
  Text("Direction")
  Spacer()
  Picker("Direction", selection: $selectorIndex) {
  ForEach(0 ..< directions.count) { index in
  Text(self.directions[index]).tag(index)
  }
  }
  .pickerStyle(SegmentedPickerStyle())
  }

  Picker("From status", selection: $fromStatus2) {
  ForEach(Self.orderStatusFromArray, id: \.self) { status in
  Text(status)
  }
  }


So far so good. If I now break it on purpose by changing line 12 to


Picker("From status", selection: "025") {


Xcode now indicates that there is an error on line 06


Generic parameter 'S' could not be inferred
1. In call to initializer (SwiftUI.Text)


Shouldn't it rather indicate that the error is on line 12 instead of 6?


Max

Max:


Best to keep in mind that an error message may not directly point to the root cause of an error, where that cause lies somewhere other than the line the error lists.


As well, it may be that Xcode is holding onto an indexed version of your code and not using your latest change...in which case using the Product menu and choosing to clean (build folder) can encourage it to let go of cached code and look at your change(s), instead.


See Xcode Help on: debugging


Ken

Error messages in SwiftUI are still really fuzzy.


I read they would improve soon…

I come from Netbeans and Java development and don't get me wrong but at least there it was pin pointing to the error in the stack thread pretty well. I am still struggeling to figure out in Xcode what piece exactly caused an error when the app crashes during execution ...

Xcode shows error on wrong line
 
 
Q