Is it possible to use optional chaining and nil coalescing simultaneously like so?
print("Meeting host: " + meeting.host?.email ?? “No host”)
You don't have to unwrap it to get it to work. That is not why the error occurred. The
?? is designed to handle such cases, after all.
The error occurs because of operator precedence. The compiler thinks that it should evaluate the
+ first, concatenating the two strings, THEN do the nil-coalescing. It sees that the second operand is not unwrapped and complains.
To make it produce the intended result, explicitly tell the compiler to evaluate the
?? first by adding brackets:
print("Meeting host: " + (meeting.host?.email ?? “No host”))