gpt4 book ai didi

ios - 在 Apple swift 2.1 中推进数组

转载 作者:可可西里 更新时间:2023-11-01 00:37:16 27 4
gpt4 key购买 nike

假设我有一个数组...

var array = [0, 1, 2, 3, 4, 5]

然后我使用 removeFirst 函数删除数组中的第一个值。

array.removeFirst()

现在数组的第一个位置有一个空值。我将如何推进数组,以便位置 2 的值向上移动到位置 1,依此类推。即数组现在看起来像这样

[1, 2, 3, 4, 5]

我必须为此创建自己的函数吗?

最佳答案

实际上,removeFirst() 方法会为您解决这个问题。 Swift Array 不可能包含“空位置”。

关于ios - 在 Apple swift 2.1 中推进数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32748325/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com