How to subclass an array class in Swift?

前端 未结 4 1737
予麋鹿
予麋鹿 2021-02-20 00:05

I am new in Swift. I have a base class:

class foo{}

I want to implement a foo collection class:

class foos: Array{}
         


        
4条回答
  •  借酒劲吻你
    2021-02-20 00:16

    Swift's Array type is a structure, and in Swift, base classes must be actual classes (that is, class Foo) and not structures.

    So you cannot do what you are trying to do via inheritance from Array, unfortunately. You could, however, store the array as a field within your class and forward methods to it, possibly implementing any protocols you want to support, et cetera.

提交回复
热议问题