Swift: different objects in one array?

后端 未结 4 1120
鱼传尺愫
鱼传尺愫 2021-02-06 14:06

Is there a possibility to have two different custom objects in one array?

I want to show two different objects in a UITableView and I think the easiest way

4条回答
  •  时光说笑
    2021-02-06 14:55

    You can use the "type" AnyObject which allows you to store objects of different type in an array. If you also want to use structs, use Any:

    let array: [Any] = [1, "Hi"]
    

提交回复
热议问题