How to remove an element from an array in Swift

后端 未结 18 2151
灰色年华
灰色年华 2020-11-28 18:38

How can I unset/remove an element from an array in Apple\'s new language Swift?

Here\'s some code:

let animals = [\"cats\", \"dogs\", \"chimps\", \"m         


        
18条回答
  •  感情败类
    2020-11-28 18:40

    This should do it (not tested):

    animals[2...3] = []
    

    Edit: and you need to make it a var, not a let, otherwise it's an immutable constant.

提交回复
热议问题