NSMenuItem -setTarget: Does it retain the target, or should one explicitly retain it?
I've seen conflicting docs on this. I know of retainArguments in NSInvocation, but I'm not sure this applies to NSMenuItem as it doesn't inherit from NSInvocation.
NSMenuItem -setTarget: Does it retain the target, or should one explicitly retain it?
I've seen conflicting docs on this. I know of retainArguments in NSInvocation, but I'm not sure this applies to NSMenuItem as it doesn't inherit from NSInvocation.
I don't believe it does. Usually target-action methods and delegate properties don't retain what they're set to, as they don't “own” their target.
Simply look at the header:
@property (nullable, weak) id target;
or in Swift:
weak var target: AnyObject? { get set }
Here we see that target is weak, meaning that it doesn't have control over the target's lifetime. In technical terms, it neither increments nor decrements the reference count. Once your target is deallocated for any reason, NSMenuItem loses it too.