我无法在return语句中理解这种语法。我不确定它是否是Swift 2.0中的新功能,但它是什么?和:意思是?这个问号是否可选,即使间隔?我很困惑,来自Objective-C背景。
private func doContainsUser(user: User) -> Bool {
let isInverted = setOfDiff.contains(user)
let wasInitiallyAdded = setOfCircleUsers.contains(user)
//What does the ? and the : mean?
return isInverted ? !wasInitiallyAdded : wasInitiallyAdded
}
答案 0 :(得分:5)
这是一个简短的if if else声明。
if isInverted {
return !wasInitiallyAdded
}
else {
return wasInitiallyAdded
}