开发者

Data Detectors in Cocoa

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 TextEdit's source code but when I checked it was 2005's version and I can't find the new source code.

Alex


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


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

Data Detectors in Cocoa

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜