I created a new SwiftUI file and using xcode, I literally added the default tabview and it is throwing an error. I attempted to reproduce this error by creating a new Xcode project but it is working perfectly. If I delete the TabView code, it builds fine.
import SwiftUI
struct TabView: View {
@State var tabSelection = 0
var body: some View {
Text("wowcool")
TabView(selection: .constant(1)) {
Text("Tab Content 1").tabItem { Text("Tab Label 1") }.tag(1)
Text("Tab Content 2").tabItem { Text("Tab Label 2") }.tag(2)
}
}
}
struct TabView_Previews: PreviewProvider {
static var previews: some View {
TabView()
}
}
Below is what I am getting:
Attempts to fix:
- Restarted Xcode
- Cleaned Project
- Deleted Derived data
- Restarted computer
Currently on Xcode 13.3 and macOS 12.3
2
Answers
You are overriding SwiftUI’s TabView. Rename your view to something else.
This is due to type conflicts (you named your custom view same as system one), so
Solution 1:
Solution 2:
Note: I would recommend solution 1 always and do not use same names as system types.