Swift: setting an optional property of a protocol

It’s impossible in Swift (yet?). Referenced from an ADF thread:

Optional property requirements, and optional method requirements that return a value, will always return an optional value of the appropriate type when they are accessed or called, to reflect the fact that the optional requirement may not have been implemented.

So it’s no surprise to get optional values easily. However, setting a property requires implementation to be guaranteed.

Leave a Comment