简体   繁体   中英

Expression type bool is ambiguous without more context

The following code is used to work in Swift 2 :

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

Now it gives the error:

Expression type bool is ambiguous without more context

The following solution worked for me:

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)

You have to wrap bool parameter by parenthesis:

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)

colon sign confuses your XCode

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM