“signingIn:Observable”用于进度条,并阻止用户在我从API获得响应之前再次单击该按钮
let validatedUsername: Observable<Bool>
let validatedPassword: Observable<Bool>
var signingIn : Observable<Bool> // Is signing process in progress
let signupEnabled: Observable<Bool> //Is signup button enabled
validatedUsername = input.username
.map { username in
return username.characters.count > 5
}
.shareReplay(1)
validatedPassword = input.password
.map { password in
return password.characters.count > 5
}
.shareReplay(1)
signupEnabled = Observable.combineLatest(
validatedUsername,
validatedPassword,
signingIn.asObservable()
) { username, password , signing in //the error at this line
username.isValid &&
password.isValid &&
!signing
}
.distinctUntilChanged()
.shareReplay(1)
}
答案 0 :(得分:0)
由于validatedUsername
和validatedPassword
都属于Observable<Bool>
类型,因此在.isValid
和username
上调用password
可能不会进行类型检查。
错误最终在上面的行上,因为编译器无法推断返回类型并提前抛出某些内容。您可以通过输入传递给combineLatest
的闭包的参数和返回类型来尝试检查是否收到更好的错误消息。
Observable.combineLatest(
validatedUsername,
validatedPassword,
signingIn.asObservable()
) { (username: Bool, password: Bool, signing: Bool) -> Bool in
return username.isValid && password.isValid && !signing
}
现在抛出的错误应该更加明显,此修复可能与删除.isValid
调用一样简单
return username && password && !signing