Skip to content

Instantly share code, notes, and snippets.

@NikolajMosbaek
Created June 1, 2022 14:59
Show Gist options
  • Save NikolajMosbaek/4b2ec644d719a82b7a525148ff3bd8b4 to your computer and use it in GitHub Desktop.
Save NikolajMosbaek/4b2ec644d719a82b7a525148ff3bd8b4 to your computer and use it in GitHub Desktop.
This code will try to match a (search) string to any of an object's string attributes
func ~=(lhs: Any, rhs: String) -> Bool {
let mirror = Mirror(reflecting: lhs)
for child in mirror.children {
guard let value = child.value as? String else { continue }
if value.localizedCaseInsensitiveContains(rhs) {
return true
}
}
return false
}
@NikolajMosbaek
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment