Removing an object from an array

How to remove a specific object from a string array.

array = ["mac","iPhone","iPad"] 

Is there a way to remove a specific row in an array, for example, for example, I wanted to remove the "iPhone" without using removeAtIndex (1)

+4
source share
1 answer

Use a filter for this purpose.

var array = ["mac","iPhone","iPad"]
array = array.filter() { $0 != "mac" }
print(array) // will print ["iPhone", "iPad"]
+5
source

Source: https://habr.com/ru/post/1622994/


All Articles