Cocoa Data Detectors

I want to add a data detector in NSTextField / NSTextView, for example, in Mail (for example, date, email address, URL, etc.).

Does anyone have an idea how to do this? I think I saw this in the TextEdit source code, but when I checked, this is the 2005 version and I cannot find the new source code.

Alex

+2
source share
2 answers

You need to set the output to format the object. Built in formatters NSDateFormatter and NSNumberFormatter .

alt text

You can define custom formatting by extending the NSFormatter class. There is a chapter in Aaron Hillegass excellent " Cocoa Programming for Max OS X " Creating NSFormatters ".

To specify dates, URL, email address, etc. inside the body of any text, you can use the hidden structure of semantic matching . This is Leopard's open API, but there is not much documentation for this. There is also an lsm command line tool that allows you to test any custom extractors you want to use. This is a C API and is not integrated into Cocoa, as far as I know, so you will need to connect it yourself

+2
source

In Snow Leopard, you can now enable Data Detectors in NSTextView by simply clicking the corresponding checkbox in the IB inspector.

+3
source

Source: https://habr.com/ru/post/894888/


All Articles