You can do this swift option if that method does not define a return value. However, functions and methods with no return type have an implicit return type of Void, as described in Functions Without Return Values.
This means that they return a value ofor an empty tuple.
This enables you to use an if statement to check whether it was possible to call the printNumberOfRooms method, even though the method does not itself define a return value. Compare the return value from the printNumberOfRooms call against nil to see if the method call was successful: if john.
The example above in Accessing Properties Through Optional Chaining attempts to set an address value for john.
Any attempt to set a property through optional chaining returns a value of type Void? The optional chaining question mark always follows immediately after the part of the expression that is optional.
The example below tries to retrieve the name of the first room in the rooms array of the john.
Because john. Similarly, you can try to set a new value through a subscript with optional chaining: john.
If you create and assign an actual Residence instance to john.