What are Opaque Types?

Hello, my name is Kobe, and I am studying Swift and iOS in South Korea.

Recently, I came across the keyword some for the first time, and as I researched it, I found the following explanation:

"In the Swift language, the some keyword is primarily used to represent Opaque Types."

The part that I'm having trouble understanding is exactly what Opaque Types are.

What type of types are Opaque Types?

1 Like

This is a good question. There are a number of ways in which opaque types have been explained, but I think an excellent starting point is found in the relevant chapter in recent versions of The Swift Programming Language:

A function or method that returns an opaque 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. Opaque types preserve type identity — the compiler has access to the type information, but clients of the module don’t.

See if the first part of that chapter (the sections before you get to "boxed" or existential types) makes some sense. I or others can clarify or point you to further resources depending on what questions arise.


Dear Xiaodi Wu, :smile:

Thank you sincerely for taking the time to read my question and providing an answer. I am truly grateful for your help, as it has greatly enhanced my knowledge.

Have a wonderful day :smiling_face_with_three_hearts: