如何从数组

时间:2017-03-09 11:02:44

标签: ios arrays swift

假设我是searching for cardType = points,如果找到它我想知道该对象的索引位置。根据给定的示例数组,此对象的索引位置为1.下面是示例数组。

[{
cardCode = MGC;
cardId = 5720663d8944bf6710c9d894;
cardType = gift;
},
{
cardCode = MPC;
cardId = 5720663d8944bf6710c9d898;
cardType = points;
}, 
{
cardCode = MAC;
cardId = 5720663d8944bf6710c9d895;
cardType = advantage;
},
{
cardCode = MCC;
cardId = 5720663d8944bf6710c9d897;
cardType = cashback;
}]

Error

1 个答案:

答案 0 :(得分:4)

您可以使用index(where:)

except (KeyboardInterrupt, SystemExit):
    print("Alarm stopped")