Skip to content

Instantly share code, notes, and snippets.

@aleksandr-lavrinenko
Created February 9, 2021 19:22
Show Gist options
  • Select an option

  • Save aleksandr-lavrinenko/c495dae9dbb7b6033b981128e37ec4a8 to your computer and use it in GitHub Desktop.

Select an option

Save aleksandr-lavrinenko/c495dae9dbb7b6033b981128e37ec4a8 to your computer and use it in GitHub Desktop.
struct Content {
let title: String
let description: String
}
fileprivate extension Array where Element == Content {
func filter(text: String) -> [Content] {
let trimmedText = text.trimmingCharacters(in: .whitespacesAndNewlines)
return filter {
$0.title.range(of: trimmedText, options: .caseInsensitive) != nil
|| $0.description.range(of: trimmedText, options: .caseInsensitive) != nil
}
}
}
let content = Content(title: "fsdfs", description: "sfdfs")
[content].filter(text: "fs")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment