How should I reason when I have to choose between a class, struct and enum in Swift?

前端 未结 7 1809
感情败类
感情败类 2020-12-08 07:16

Since classes, structs and enums all has constructors, properties and computed properties, how should I reason when choosing between them?

7条回答
  •  感动是毒
    2020-12-08 07:31

    The most important difference between classes and other named types (structs/enums) is:

    Structs cannot be subclasses (or substructs, so to speak) of anything. Nor can they be subclassed themselves. Inheritance is completely out of picture with structs. Same goes for enums.

提交回复
热议问题