In this Swift Tutorial we will tell you how to filter an array of Ints in Swift

Before you start please Create or open a Swift Playground and name it “ Swift Tutorial – How to Filter Array in Swift”

Follow Along

Let’s create an array of ints to work with

Open a swift playground and type:

Now, let’s create a function call that will filter our array to create a new array with values less than 50:

Now you’ll see the results. You must see [30, 34, 2] in your console.

If we want to create an array with the values less than 50 but greater than or equal to 30, we can do the following:

As a result you will see the following in your playground:

Filter array in Swift

Try more Swift tutorials at 👉 Swift Tutorials Navigation

Made using Swift 3

This lesson is a part of Swift Tutorials and Lessons created by the Team. Feel free to save and share this post to social if you find this lesson useful or helpful.