Open madsmtm opened 9 months ago
When leaving this scope, obj will be released and sel will not be called. How to solve.
-[NSMenuItem target]
is a weak property, which means that it will not by itself prevent the object from being deallocated.
You will have to keep the object that you want to use as the target around manually, probably by storing the Id<...>
in a struct somewhere (depends on your setup).
Thank you. I know what to do, okay
It is common in AppKit and UIKit to have methods that expect to run a selector on an object. These are usually legacy methods that were introduced before blocks were added to / common in Objective-C, or work this way because the event bubbles upwards.
Examples include
NSMenuItem
,NSNotificationCenter
andUIGestureRecognizer
.It would maybe be nice if we had some object wrapper around closures, such that one didn't have to go through the whole of
declare_class!
just to handle an event?I'm thinking something similar to: