NSTokenField and deleting tokens

admin

Administrator
Staff member
My app allows users to attach tags to certain model objects (subclasses of NSManagedObject). The Tag class is also a subclass of NSManagedObject. I decided to use
Code:
NSTokenField
to display the tags, where each token holds an instance of Tag as the represented object. It all works pretty good but I'm stuck in situations where the user deletes a token as I want to check whether the associated Tag has become obsolete and should be deleted.

I was expecting a method in
Code:
NSTokenFieldDelegate
or
Code:
NSTokenFieldCellDelegate
which would allow me to intercept and check a delete action on a token.

After some googling I found <a href="http://subjectiveobserver.wordpress.com/2011/03/14/more-than-token-problems/" rel="nofollow noreferrer">this post</a> addressing the topic. I implemented the suggested method
Code:
controlTextDidChange:
in my controller (the delegate of the token field). Upon inspecting the control that is passed as an argument, it revealed to be an instance of
Code:
NSTokenTextView
for which I cannot find any documentation (probably a private class).

Has anybody run into this and found a solution to gracefully delete tokens while maintaining the underlying model of represented objects?

EDIT

I found <a href="https://stackoverflow.com/questions/4357624/callback-for-deleting-nstokenfieldcell">this</a> as well, which seems to suggest that for some reason it just is not designed to work like the rest of us would expect.