首页 > 解决方案 > 读取数组中的结构

问题描述

我创建了一个结构并将其附加到一个数组中。如何在数组中读取该结构?

struct TOitemData {
    let BestItem: String?
    let BestQty: Int?
    let BestTotal: Int?
}

class TObyItemVC: UIViewController{

    var TOitemArray: [TOitemData] = []
    TOitemArray.append(TOitemData(BestItem: "1/2 Chicken with chips", BestQty: 54, BestTotal: 4500))
    TOitemArray.append(TOitemData(BestItem: "Cheese hamburger and chips", BestQty: 45, BestTotal: 4210))

}

如何获得第 2 行 BestQty,即 45?

标签: swift

解决方案


TObbyItemArray[1].BestQty 获取第二行,然后是 BestQty 的值


推荐阅读