Use contains instead:

let arr = ["Hello","Bye","Halo"]
let filtered = arr.filter { $0.contains("lo") }
print(filtered)

Output

["Hello", "Halo"]

Thanks to @user3441734 for pointing out that functionality is of course only available when you import Foundation

Answer from luk2302 on Stack Overflow
🌐
Apple Developer
developer.apple.com › documentation › swift › sequence › filter(_:)-5y9d2
filter(_:) | Apple Developer Documentation
Returns an array containing, in order, the elements of the sequence that satisfy the given predicate.
🌐
Programiz
programiz.com › swift-programming › library › array › filter
Swift Array filter() (With Examples)
The filter() method returns all the elements from the array that satisfy the provided condition. The filter() method returns all the elements from the array that satisfy the provided condition. Example var numbers = [2, 3, 6, 9] // return all the elements greater than 5 var result = ...
Discussions

Filter array with another array - Using Swift - Swift Forums
I would like to create a new array of strings that dont contain strings from another array. I have it working in the long form. But would like to learn a more Swift way of doing it The return filteredList would be ["mu… More on forums.swift.org
🌐 forums.swift.org
0
June 29, 2022
How To Filter Array by Range?
Swift is a general-purpose programming language built using a modern approach to safety, performance, and software design patterns. ... I am having problem filtering an array of custom objects by range. I try to access each objects .Name property which is a NSString type by a range of characters. More on reddit.com
🌐 r/swift
6
4
December 6, 2015
Filtering array of objects by strings in another array.
Use the handy-dandy filter method: matches = matches.filter { !matchIDsToDelete.contains($0.matchID) } More on reddit.com
🌐 r/swift
4
2
October 30, 2015
How to effectively filter array by another array? ( In functional paradigm ) - Using Swift - Swift Forums
Consider following task. Let A be a list of Comparable items. Let B be a list of Comparable items. Entries in these lists can be compared. Output is a list of entries in A that are not in the list B. Two conditions. Assume A and B are sorted. Count of the same entries are considered as difference ... More on forums.swift.org
🌐 forums.swift.org
0
December 27, 2018
People also ask

How do you apply a filter on an array of objects in Swift?
To filter an array of objects in Swift, you can define a filtering condition using a closure that checks specific properties of the objects and then use the filter function to create a new array with the filtered elements.
🌐
dhiwise.com
dhiwise.com › post › efficient-data-refinement-with-swift-array-filter-strategies
Mastering Swift Array Filter: A Comprehensive Guide
How does the filter() function work in Swift?
The filter() function in Swift evaluates each element of an array based on a given condition and returns a new array containing only the elements that satisfy that condition.
🌐
dhiwise.com
dhiwise.com › post › efficient-data-refinement-with-swift-array-filter-strategies
Mastering Swift Array Filter: A Comprehensive Guide
What is the purpose of the filter function in Swift?
The filter function in Swift is used to extract elements from an array that match specified conditions, providing a streamlined way to refine and process data efficiently.
🌐
dhiwise.com
dhiwise.com › post › efficient-data-refinement-with-swift-array-filter-strategies
Mastering Swift Array Filter: A Comprehensive Guide
🌐
Sarunw
sarunw.com › posts › swift-array-filter
How to Filter an Array in Swift | Sarunw
July 10, 2023 - Swift Array has an instance method, filter(_:), that removes unwanted elements from the resulting array.
🌐
Swift Forums
forums.swift.org › using swift
Filter array with another array - Using Swift - Swift Forums
June 29, 2022 - I would like to create a new array of strings that dont contain strings from another array. I have it working in the long form. But would like to learn a more Swift way of doing it The return filteredList would be ["music", "unicorns rainbow walkers"] let removelist : [String] = ["nerf", "magic beans"] let originalList : [String] = ["nerf", "music", "unicorns rainbow walkers", "magic beans"] // tried this but not exactly working //let filtered = originalList.filter { $0.contains(where: { rem...
Find elsewhere
🌐
Hacking with Swift
hackingwithswift.com › example-code › language › how-to-remove-items-from-an-array-using-filter
How to remove items from an array using filter() - free Swift example code and tips
May 28, 2019 - The filter() method goes over all the items in an array (or indeed any kind of collection), and returns a new array containing items that pass a test you specify. ... NEW You don’t need more Swift tutorials.
🌐
Bugfender
bugfender.com › blog › swift-arrays
Swift Arrays: Map, Filter, Reduce & Sort Explained | Bugfender
November 7, 2025 - Swift arrays are value-type data structures that copy on write, ensuring predictable behavior and thread safety. We should use sort() or sorted() to organize data, and choose filter() to extract only the elements we need.
🌐
Brightec
brightec.co.uk › home › blog › how to filter, map, and reduce in swift
Swift Basics: Mapping, Filtering, and Reducing in Swift |… | Brightec
August 16, 2023 - From Swift 5.2, we're now able to use key paths in place of the closures above, so we can change the map to let userIds = users.map(\.id) compactMap is a special type of map that filters out any nil elements. This is helpful when your mapping function could fail and you want to ignore those failures e.g. converting an array of strings to an array of URLs (not all strings are valid URLs).
🌐
DhiWise
dhiwise.com › post › efficient-data-refinement-with-swift-array-filter-strategies
Mastering Swift Array Filter: A Comprehensive Guide
September 10, 2024 - In the world of Swift development, manipulating arrays efficiently is a common task. One fundamental operation when working with arrays is filtering - the process of selecting only the elements that meet specific criteria.
🌐
Reddit
reddit.com › r › swift › comments › 56808k › how_to_filter_array_by_range
How To Filter Array by Range? : r/swift
December 6, 2015 - However I keep getting a warning ("comparing an non optional value of NSRange to nil always returns true") and sure enough my filtered array is the same as my input array. I do not know how to proceed.
🌐
Better Programming
betterprogramming.pub › multi-select-filter-in-swift-part-1-5f4da79989b9
Multi-select Filter in Swift
January 17, 2023 - It means that if we pass, let’s say, the PhoneDiskSpaceFilter to the PhonePriceFilter initializer, the provided initial array of phones will first be filtered with disk space conditions, and only then the result will be passed to the PhonePriceFilter for further filtering.
🌐
Use Your Loaf
useyourloaf.com › blog › swift-filtering-with-predicates
Swift Filtering With Predicates
May 11, 2020 - I work through how you can use NSPredicate in Swift to filter a list of value types using an increasingly complicated combination of search criteria.
🌐
Reddit
reddit.com › r/swift › filtering array of objects by strings in another array.
r/swift on Reddit: Filtering array of objects by strings in another array.
October 30, 2015 -

I have an array of Match objects [Match] with a string property of matchID. I also have an array of strings.

I would like to remove the Match object where matchID equals any string in the array.

I currently have:

                var matches = [Match]
                var matchIDsToDelete = [String]

                for match in matches {
                    for id in matchIDsToDelete {
                        if match.matchID == id {
                            // remove that item from array
                        }
                    }
                }

My concern is removing the object from the array as I'm enumerating. I believe there will be consequences. Any suggestions? I would also love a functional solution as I'm currently reading more about functional programming.

Thanks!

🌐
DhiWise
dhiwise.com › post › how-to-choose-between-swift-filter-vs-compactmap
Swift filter vs compactMap: Understanding the Key Differences
August 14, 2024 - This is especially useful when working with optional values or transforming nested arrays. The filter method in Swift is a powerful tool for creating a new array containing only the elements that satisfy a given condition.
🌐
Mahi Garg
mahigarg.github.io › blogs › filter-operator-swift
Filter Operator: Swift · Mahi Garg
May 29, 2022 - Since the filter operator is present in Iterator, it can be used with all three collections ie Array, Set, and Dictionary.
🌐
W3Schools
w3schools.com › jsref › jsref_filter.asp
W3Schools.com
The filter() method creates a new array filled with elements that pass a test provided by a function.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › filter
Array.prototype.filter() - JavaScript | MDN
December 13, 2025 - The following example uses filter() to create a filtered array that has all elements with values less than 10 removed.
🌐
Hacking with Swift
hackingwithswift.com › read › 39 › 6 › filtering-using-functions-as-parameters
Filtering using functions as parameters - a free Hacking with Swift tutorial
May 28, 2019 - We're going to add the ability ... a specific string. This will work by giving PlayData a new array, filteredWords, that will store all words that matches the user's filter....
🌐
Swift Forums
forums.swift.org › using swift
How to effectively filter array by another array? ( In functional paradigm ) - Using Swift - Swift Forums
December 27, 2018 - Consider following task. Let A be a list of Comparable items. Let B be a list of Comparable items. Entries in these lists can be compared. Output is a list of entries in A that are not in the list B. Two conditions. …
🌐
Codecademy
codecademy.com › docs › swift › arrays › .filter()
Swift | Arrays | .filter() | Codecademy
June 28, 2023 - The .filter() method takes an array and returns a new array with only elements that meet the condition stated in the filter. If none of the elements meet the condition stated in the filter, the method returns nil.