swift - 读取数组中的结构
问题描述
我创建了一个结构并将其附加到一个数组中。如何在数组中读取该结构?
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?
解决方案
TObbyItemArray[1].BestQty 获取第二行,然后是 BestQty 的值
推荐阅读
- git - 如何在 vagrant VM 中使用 cygwin、git bash 和 git 在 Windows 上设置 git?
- java - 具有不同模式的休眠 @Inheritance(strategy=InheritanceType.JOINED) 会导致错误 (HHH000099)
- python - ValueError: 操作数不能与形状一起广播 (2,3) (998,)
- python - Python Eve:使用事件挂钩在 auth_field 中添加 _id 值
- testing - 如何为自制公式编写测试?
- r - 如何使用 R 从引号中获取数字和主题标签?
- php - 在包含其他数组的关联数组中获取多值
- c# - 使用 ReadLine 输入来控制我想在数组中使用哪个项目并获取它们的项目编号?
- node.js - MongoDB:手动锁定和解锁集合
- python - Pandas/Python 将月末行从数据框中提取到单独的数据框中