So I mistakenly name my view SegmentedControl
, which duplicates SwiftUI's:
public struct SegmentedControl<SelectionValue, Content> : View where SelectionValue : Hashable, Content : View {
My code:
import SwiftUI
enum Architecture: String, CaseIterable {
case mvc
case mvvm
case viper
}
// no compile error here. !!!!
// vvvvvvvv bad name, should call it something else!!!!
struct SegmentedControl: View {
@State private var selectedArchitecture: Architecture = .viper
var body: some View {
Form {
HStack {
Text("Architecture:")
.bold()
// error here:
// 'SegmentedControl.Type' is not convertible to '() -> SegmentedControl'
SegmentedControl(selection: $selectedArchitecture) {
ForEach(Architecture.allCases, id: \.self) { architecture in
Text(architecture.rawValue).tag(architecture)
}
}
}
}
}
}
#if DEBUG
struct SegmentedControl_Previews: PreviewProvider {
static var previews: some View {
SegmentedControl()
}
}
#endif
But the compiler don't show name conflict error. instead, show
'SegmentedControl.Type' is not convertible to '() -> SegmentedControl'
At the site where I init's a SegmentedControl
Should the compiler give duplicate type name error instead?