Skip to content

Instantly share code, notes, and snippets.

@Oil3
Last active March 2, 2024 04:36
Show Gist options
  • Save Oil3/82fb57a47adcc7c1a81db69f115c3b83 to your computer and use it in GitHub Desktop.
Save Oil3/82fb57a47adcc7c1a81db69f115c3b83 to your computer and use it in GitHub Desktop.
WKWebView search / find for MacOS swift
//Actually it is built-in for Mac as well, no need of 3 pages of Js,
//In the contentview:
@State private var searchText = ""
//inside its navigationsplitview/stack the automatic field
.searchable(text: $searchText)
//In the view:
@Binding var searchText: String
if !searchText.isEmpty {
let findConfiguration = WKFindConfiguration()
findConfiguration.caseSensitive = false
findConfiguration.wraps = true
nsView.find(searchText, configuration: findConfiguration) { result in
// Handle the results of the search
print("Matches found: \(result)")
}
//that's it, need activate cmd+F and cmd+G and perfect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment