Can I receive a callback whenever an NSPasteboard is written to?

后端 未结 6 1905
迷失自我
迷失自我 2020-12-02 09:26

I\'ve read Apple\'s Pasteboard Programming Guide, but it doesn\'t answer a particular question I have.

I\'m trying to write a Cocoa application (for OS X, not iOS) t

6条回答
  •  一个人的身影
    2020-12-02 09:39

    I have a solution for more strict case: detecting when your content in NSPasteboard was replaced by something else.

    If you create a class that conforms to NSPasteboardWriting and pass it to -writeObjects: along with the actual content, NSPasteboard will retain this object until its content is replaced. If there are no other strong references to this object, it get deallocated.

    Deallocation of this object is the moment when new NSPasteboard got new content.

提交回复
热议问题