数组字典的常见操作

4/22/2021 Swift

    [toc]

    数组 字典
    shoppingList.append("Flour")
    shoppingList += ["Baking Powder"]
    shoppingList += ["Chocolate Spread", "Cheese", "Butter"]
    let mapleSyrup = shoppingList.remove(at: 0)
    let apples = shoppingList.removeLast()
    var firstItem = shoppingList[0]
    shoppingList[0] = "Six eggs"
    shoppingList[4...6] = ["Bananas", "Apples"]
    shoppingList.insert("Maple Syrup", at: 0)
    sixDoubles.count
    shoppingList.isEmpty

    //遍历
    //for-in, enumerated()
    for item in shoppingList {
    print(item)
    }

    //需要索引,用 enumerated()
    for (index, value) in shoppingList.enumerated() {
    print("Item (String(index + 1)): (value)")
    }
    Last Updated: 4/21/2021, 8:41:59 PM