我在swift中有一个if语句,我无法弄清楚如何设置。我想检查两个变量并检查它们是否不等于某个值。然后,应将不等于特定值的变量设置为新变量。我正在比较两个变量。例如,如果x!= y则x应该被赋予一个新值,或者如果z!= y那么z也应该被赋予一个新值。
这是我的代码:
if (message.ReceiverId != self.loggedInUserUid || message.senderId != self.loggedInUserUid) {
//Print the variable that is not equal to the loggedInUserUid
//and set it to a variable.
}
答案 0 :(得分:1)
如下所示?
if message.ReceiverId != self.loggedInUserUid {
var newVariable = message.ReceiverId
} else if message.senderId != self.loggedInUserUid {
var newVariable = message.senderId
}
答案 1 :(得分:1)
为什么你必须有一个"或"声明?如果"?
,对于"否则是不够的{ firstPart= "" }