Merge Swift Array with same superclass

前端 未结 3 1577
一个人的身影
一个人的身影 2020-12-19 08:25

I\'m trying to find the best way to merge Swift arrays, that are not of same type, but they have same superclass. I\'ve already read all the tutorials so I know I can use:

3条回答
  •  -上瘾入骨i
    2020-12-19 08:52

    In addition to Martin's answer, you could create a protocol that all of the classes conform to and then when creating your array, make it's type that protocol.

    Then you can add any of the classes to it without casting.

提交回复
热议问题