1

I have an array.

var array_var: [String] = [
"https://www.filepicker.io/api/file/XXXXXXXXXXXXX/convert?fit=crop&w=200&h=200&rotate=exif",
"https://www.filepicker.io/api/file/XXXXXXXXXXXXXX/convert?fit=crop&w=320&h=300&rotate=exif",
"https://www.filepicker.io/api/file/XXXXXXXXXXXXXXXX",
"https://www.filepicker.io/api/file/XXXXXXXXXXXXXXXX"
]

So I just want to remove(exclude) the elements that contains the string convert?fit=crop from the array.

So how can we remove them by using Swift??

2 Answers 2

4

You can use filter method:

array_var = array_var.filter {
    $0.rangeOfString("convert?fit=crop") == nil
}
Sign up to request clarification or add additional context in comments.

Comments

0

A simple way to do it

var array_var: [String] = [
"https://www.filepicker.io/api/file/XXXXXXXXXXXXX/convert?     fit=crop&w=200&h=200&rotate=exif",
"https://www.filepicker.io/api/file/XXXXXXXXXXXXXX/convert?fit=crop&w=320&h=300&rotate=exif",
"https://www.filepicker.io/api/file/XXXXXXXXXXXXXXXX",
"https://www.filepicker.io/api/file/XXXXXXXXXXXXXXXX"
]

var newArray: [String] = []


for i in 0...array_var.count - 1 {
if array_var[i].rangeOfString("convert?fit=crop") != nil {

    newArray.append(array_var[i])


}
}
array_var = newArray

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.