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

108486 次浏览

myArray.removeAll()

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

myArray.removeAll()

var firstElement = myArray.first!
myArray.removeAll()
myArray.append(firstElement)

for index in stride(from: myArray.count - 1, through: 0, by: -1) {
myArray.removeAtIndex(index)
}

myArray = filter(myArray, { (obj) -> Bool in
return false
})

myArray = myArray.filter{ (obj) -> Bool in
return false
}

for index 0..<myArray.count {
myArray.removeAtIndex(index)
}

for index in reverse(0..<myArray.count) {
myArray.removeAtIndex(index)
}

for _ in myArray
{
myArray.removeAtIndex(0)
}

Syntax :  public func removeAllObjects()
Eg.:   mainArray.removeAllObjects

Syntax : public func removeObjectAtIndex(index: Int)
Eg.: mainArray.removeObjectAtIndex(5)

Syntax : public func removeLastObject()
Eg.: mainArray.removeLastObject()

Syntax : public func removeObject(anObject: AnyObject, inRange range: NSRange)

Syntax : public func removeObject(anObject: AnyObject)

Screenshot 1

existingArray = []

existingArray.removeAll()

for index in myArray.indices {
// Do stuff
}