Optional<Error>'s localizedDescription vs error.debugDescription

Quite odd behaviour, isn't it?

var error: Error?

_ = error!.localizedDescription // ✅
_ = error.debugDescription      // ✅

_ = error.localizedDescription  // 🛑 Value of optional type '(any Error)?' must be unwrapped to refer to member 'localizedDescription' of wrapped base type 'any Error'
_ = error!.debugDescription     // 🛑 Value of type 'any Error' has no member 'debugDescription'

It looks a little whimsical, I guess, but this seems expected. localizedDescription is a function implemented by any Error, and debugDescription is a function implemented by Optional.

But not vice versa.

3 Likes