Usage of Generics in Foundation API

This is sort of based on some research I did into a method in Foundation. The method in question is decode(_:from:) and according to the developer docs, this method is:


Declaration

func decode<T>(_ type: T.Type, from data: Data) throws -> T where T : Decodable


Definition

Returns a value of the type you specify, decoded from a JSON object.


In this method, Apple used T.Type for the first parameter. From a previous forum thread (see link below), I understand what T.Type means:


T.Type is a notation to speicify a type which can hold a type object of T (not an instance of T)....


My question is that I don't understand how would I know as a developer that I can add have this .Type syntax available to use. My first place was to check was in the Generics Docs, but no result. I'm sure it's documented somehwere, otherwise, how would anyone know how to use it?


Any help on where this is documented would be appreciated, I'm just trying to understand this properly.



Link to Previous Forum:

h ttps://forums.developer.apple.com/thread/109664?q=Generics*


P.S. I would reply to this thread listed above, however, I am having troubles accesing that thread... this is why I made this one!

Answered by OOPer in 335427022

Unfortunately, not all Swift features are well-documented. Some features are only described in the Reelase Notes of Xcode, some features are only referred to in some Evolution articles.


But in this case, you can find it in the Swift Book.

Metatype Type


The term `meta` is used in various ways so I avoided using the word `metatype` in another thread, but it definitely is Metatype - type for types.

Accepted Answer

Unfortunately, not all Swift features are well-documented. Some features are only described in the Reelase Notes of Xcode, some features are only referred to in some Evolution articles.


But in this case, you can find it in the Swift Book.

Metatype Type


The term `meta` is used in various ways so I avoided using the word `metatype` in another thread, but it definitely is Metatype - type for types.

Thank you!! Perfect. This was exactly what I was looking for!

Usage of Generics in Foundation API
 
 
Q