0

If I have an array of strings, the formula is simple, it's something like:

let filteredArray = stringArray.filter({ $0.contains(filterWord)})

However, if I have an array of structures each with a property called "title", how do I filter and create an array of these structures with a keyword?

struct Item: Codable {
var title: String = ""
}

Thanks in advance.

1 Answer 1

3

Since $0 is the current item you’re looking at just add the property you want to filter:

let filteredArray = stringArray.filter({ $0.title.contains(filterWord)})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.