user5215130
user5215130

Reputation:

Value of type 'Array<Any>?' has no member 'removeAtIndex'

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

Answers (2)

user9106403
user9106403

Reputation:

Swift 4

 var cards:Array<Any>? = []
 let i : Int = (sender.layer.value(forKey: "index")) as! Int
 cards?.remove(at: i)

Upvotes: 1

Catherine
Catherine

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

Related Questions