Opaque pointer is a special case of data type, which is declared to be a pointer while the data structure is hidden or an unspecified type. Its implementation and type information are unrevealed to the users.

I am not going to discuss the opaque pointer in C here, since it is a book on Swift. In Swift, the corresponding type is COpaquePointer, which is used to describe the pointers cannot be represented in Swift. If a pointer type can be represented in Swift, the pointer should be UnsafePointer<T>, otherwise, COpaquePointer is used as a supplement.

In early beta age of Swift, there were quite some of APIs returning or accepting values with COpaquePointer type. But as the improvement of Swift, most of them are categorized to its correct Unsafe type. Now there is almost no COpaquePointer in Cocoa's API, which is a good news for us developers. Currently, the most common use cases of COpaquePointer are converting a pointer type between two Unsafe pointers. We could use the init methods of both types to do the conversion:

struct UnsafeMutablePointer<T> :
                    RandomAccessIndexType,
                    Hashable,
                    NilLiteralConvertible {

    //..

    init(_ other: COpaquePointer)

    //..
}

struct COpaquePointer :
                Equatable,
                Hashable,
                NilLiteralConvertible {
    //..

    init<T>(_ source: UnsafePointer<T>)

    //..
}

COpaquePointer is a middle-man in pointer conversion, we can convert a pointer to COpaquePointer and then convert it to any other type of pointer. Of course, all these operations are not safe. Unless you really know what you are doing, never do it!

Another important form of pointer in Swift is a pointer to a function. It is not rare in C, which points to a function memory. In Swift, it is called CFunctionPointer.

If it is in C:

int * test() {}

In Swift, this function pointer would be:

CFunctionPointer<()->CInt>

Same as other C pointers in Swift, it is only used when work interoperability with C, in some C APIs should be called with a function pointer as an argument. CFunctionPointer could be initiated from a COpaquePointer, but in pure Swift, all details of C pointers and addresses are hidden. If we need to get a C function address, the only way would be getting from return value of a C API. We cannot use the Swift standard library to create a CFunctionPointer, but only pass it from functions.