What does <> (angle brackets) do on class names in swift?

后端 未结 1 1686
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-01 15:17

In a class declaration what is the use of <> angle brackets and the parameters declared inside in swift? Like as:

public class ClassName

        
相关标签:
1条回答
  • 2021-01-01 15:44

    It makes the class generic. The Swift standard library doesn't have a lot of examples of generic classes, but it has some very well-known generic structs and enums:

    public struct Array<Element> : CollectionType, MutableCollectionType, _DestructorSafeContainer
    
    public struct Dictionary<Key : Hashable, Value> : CollectionType, DictionaryLiteralConvertible
    
    public enum Optional<Wrapped> : _Reflectable, NilLiteralConvertible
    

    Read more about generics under “Generics” in The Swift Programming Language.

    0 讨论(0)
提交回复
热议问题