guard let currentAssignee = self.assigneeUserIdFor(groupId: groupID),
let newAssignee = conversation.conversationAssignee,
!newAssignee.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty,
newAssignee != currentAssignee else {
completion(response)
return
}
print("looking for updating metadata")
The return statement is called when I run the function and the function exits. I want the function to go to the print statement and continue to update the metadata.
Because there is no loop, I cannot use a continue or a break.
How can I make this happen? Do I need to change the conditions in the guard statement?
The whole point of a guard statement is to exit the scope early. What would be the point of this statement if it executed the print statement regardless of whether the guard conditions were met?
I don't understand how this would achived the behavior you're looking for either.
If the newAssignee is not the same as the current one, the call to the updateAssignee
function is done after the guard block. so, that is why I need the scope to continue even if the guard block fails..
So then why are you using a guard block at all if you want the print statement to execute regardless of whether the conditions are met? You should post the entire function for more context.
The purpose of guard is to guarantee that everything in it succeeds before proceeding with the rest of a function — if any part of it fails, the else block gets executed, which includes leaving the function (or whatever scope you're in).
From your second message, it sounds like perhaps the newAssignee != currentAssignee condition doesn't actually require you to leave at that point, so you may want to extract that check from the guard statement and use it in an if or switch statement afterward.