我遇到以下错误消息:
表达式类型不明确,没有更多上下文
在此行上:
Picker(selection: $contact.type, label: Text("Select Testing Type"))
当我在Text中添加更多行时,错误弹出。有人有同样的问题吗?该如何解决?
我正在使用Catalina和iOS11。
此处是整个代码段:
导入合并 导入SwiftUI
class Contact: ObservableObject {
var objectWillChange = PassthroughSubject <Void, Never>()
static let types = ["Functional", "Automation", "Manual", "Mobile App", "Performance", "Security", "E2E", "Integration"]
static let services = ["HandsOn Testing", "Test Management", "Test Process Setup", "Training", "Test Leadership"]
var type = 0 {didSet { update()}}
var service = 0 {didSet { update()}}
var name = "" {didSet { update()}}
var company = "" {didSet { update()}}
var city = "" {didSet { update()}}
var email = "" {didSet { update()}}
var isValid: Bool{
if name.isEmpty || company.isEmpty || city.isEmpty || email.isEmpty {
return false
}
}
func update(){
//add log
objectWillChange.send()
}
}
struct ContentView: View {
@ObservedObject var contact = Contact()
var body: some View {
NavigationView {
Form {
Section {
Picker(selection: $contact.type, label: Text("Select Testing Type"))
{ ForEach(0..<Contact.types.count)
{Text(Contact.types[$0]).tag($0)
}}
Picker(selection: $contact.service, label: Text("Select Testing Service"))
{ForEach(0..<Contact.services.count)
{Text(Contact.services[$0]).tag($0)
}}
}
Section {
TextField($contact.name, placeholder:Text("Name"))
TextField($contact.company, placeholder:Text("Company"))
TextField($contact.city, placeholder:Text("City"))
TextField($contact.email, placeholder:Text("Email"))
}
Section {
Button(action: {
self.sendForm()
}) {
Text("Send Form")
}
}
.navigationBarTitle(Text("Contact us"))
}
}}
func sendForm(){
}}
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
答案 0 :(得分:0)
如果您按模块中的原样复制/粘贴代码,那么我认为问题出在
ForEach(0 .. << strong> Contact .types.count)
您使用类型名称而不是变量名称联系人