Reputation:
I tried to use removeAtIndex function to delete item from my array, but when I run the code I get an error that "Value of type 'Array?' has no member 'removeAtIndex'". Maybe somebody had the same problem and can help me to solve it, here is my code:
var cards:Array<Any>?
let i : Int = (sender.layer.value(forKey: "index")) as! Int
cards.removeAtIndex(i)
Thank You!
Upvotes: 2
Views: 4044
Reputation:
Swift 4
var cards:Array<Any>? = []
let i : Int = (sender.layer.value(forKey: "index")) as! Int
cards?.remove(at: i)
Upvotes: 1
Reputation: 682
var arr = Array<Any>()
arr = ["1","2","3"]
arr.remove(at: 2)
print(arr) // It prints ["1","2"]
In Array, we don't have removeAtIndex() . Use remove(at: Int)
Upvotes: 1