Swift:删除所有数组元素 [英] Swift: delete all array elements

查看:637
本文介绍了Swift:删除所有数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用这样的for循环删除所有数组元素:

I am trying to delete all array elements with a for loop like this:

for index 1...myArray.count {
   myArray.removeAtIndex(index)
}

但它没有'工作,我在建造之前得到这个错误:

But it doesn't work, I get this error before bulding:


'for'陈述中的预期';'

Expected ';' in 'for' statement


推荐答案

有一种方法(实际上是一种功能)

There is a method (actually a function)

myArray.removeAll()

这篇关于Swift:删除所有数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆