NSTextFinder example wanted

Hi All,

I 'm developing a SwiftUI based Mac app that amongst other things has a text editor. The editor is subclassed from NSTextView and some additional functionality added. It is also wrapped in a NSViewRepresentable to make it a SwiftUI View. I'd like to add a standard Find/Replace functionality to it - menu items, find/replace bar or panel, and etc.

I did read the documentation on NSTextFinder and NSTextFinderClient, but it's kind of hard to see the full picture how these classes should be used together. Also, since this is SwiftUI based app, I'm not using story boards.

If you know any examples, tutorials, or just code snippets that could help me get start, please share. Amy links are greatly appreciated.

Thanks!

Hi @ilia_saz, we do have some sample code projects directly related to TextKit:

Those projects also link to related WWDC presentations.

If you're interested in getting find-and-replace functionality "out of the box", I'd recommend looking at the usesFindPanel or usesFindBar properties of NSTextView; it already supports NSTextFinder.

NSTextFinder example wanted
 
 
Q