Removing object from array in Swift 3

前端 未结 13 2111
余生分开走
余生分开走 2020-12-08 12:49

In my application I added one object in array when select cell and unselect and remove object when re-select cell. I used that code but give me error.

extens         


        
13条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 13:05

    Try this in Swift 3

    array.remove(at: Index)
    

    Instead of

    array.removeAtIndex(index)
    

    Update

    "Declaration is only valid at file scope".
    

    Make sure the object is in scope. You can give scope "internal", which is default.

    index(of:) to work, class should conform to Equatable

    提交回复
    热议问题