A function or method with an opaque return type hides its return value’s type information. Instead of providing a concrete type as the function’s return type, the return value is described in terms of the protocols it supports. Hiding type information is useful at boundaries between a module and code that calls into the module, because the underlying type of the return value can remain private. Unlike returning a value whose type is a protocol type, opaque types preserve type identity, the compiler has access to the type information, but clients of the module don’t.
For example, the function in the following example returns a trapezoid without exposing the underlying type of that shape.
Source: https://docs.swift.org/swift-book/LanguageGuide/OpaqueTypes.html
Top comments (0)