Data Detectors in Cocoa

前端 未结 2 1262
长情又很酷
长情又很酷 2021-01-15 03:10

I want to add a data detector in an NSTextField / NSTextView like in Mail (e.g. date, email, URL, etc).

Does anyone have an idea how to do this ? I think I saw it in

相关标签:
2条回答
  • 2021-01-15 03:51

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

    0 讨论(0)
  • 2021-01-15 04:13

    You need to set the formatter outlet of the object. Built in formatters are NSDateFormatter and NSNumberFormatter.

    alt text

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

    To detect dates, url, email address, etc. within the body of some text, you can use the Latent Semantic Mapping Framework. It's a public API as of Leopard but there isn't a great deal of documentation for it. There is also a command line tool called lsm that would allow you to test any custom extractors you want to use. It is a C API and not integrated into Cocoa as far as I know so you'd need to wire it up yourself

    0 讨论(0)
提交回复
热议问题