Search code examples
swiftuiviewnsview

Tag for subclass of NSView returning -1


I have a class that is a subclass of NSView. When an instance of this view is clicked, it runs notificationCenter.post(name: .tileClicked, object: tag). However, the tag is always -1. How do I ensure that my subclass has a tag?


Solution

  • The tag property of NSView returns -1. If you want it to return a different value, you must create a subclass of NSView in which you override the property. (This is different from UIView, which has a mutable tag property.)