DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 967,611 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for Opaque Types in Swift
Saif Ullah Sajid
Saif Ullah Sajid

Posted on

Opaque Types in Swift

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

swiftui #iosdevelopment #iosdevelopers #iosdeveloper #apple #programming #coding #applicationdevelopment #iosdev #appdevelopment #learning #knowledgesharing

Top comments (0)

🌚 Life is too short to browse without dark mode