表达式bool是模糊的,没有更多的上下文

时间:2018-05-07 09:51:13

标签: ios swift swift4

以下代码用于Swift 2

let endpoint = EndpointManager(endpoint: userType == .Pro ? .ProFollowing(identifier, url) : .FanFollowing(identifier, url), method: .get, parameters: nil)

现在它给出错误:

  

表达式bool不明确没有更多上下文

以下解决方案对我有用:

var following : Endpoint
if userType == .pro {
        following = Endpoint.proFollowing(identifier,url)
}
else {
        following = Endpoint.fanFollowing(identifier,url)
}
let endpoint = EndpointManager(endpoint: following, method: .get, parameters: nil)

1 个答案:

答案 0 :(得分:0)

你必须用括号括起bool参数:

let isProFollowing = userType == .Pro ? .ProFollowing(identifier, url)
let following: YourEnumType = isProFollowing ? .ProFollowing(identifier, url) : .FanFollowing(identifier, url)
let endpoint = EndpointManager(endpoint: following, method: .get, parameters: nil)

冒号符号会混淆您的XCode