src/macos/api-wrappers/OnActionExtensionSpecs.md
NSControl.onAction is a convenience extension (defined in HelperExtensionsTestable.swift) that
replaces the classic target/action pair with a stored closure: assigning control.onAction = { … }
wires the control's target/action to invoke that closure, and reading the property back returns the
stored closure. It's the backbone of AppearanceTab's Pro-lock wrap pattern — a control's existing
action is read, captured as original, and re-wrapped so a Pro-gate check can run first and then
optionally fall through to original?(control).
let original = control.onAction; a broken getter would leave original nil and orphan
the underlying action (the regression these tests pin).onAction = nil clears target, action, and the stored closure.original closure must survive later reassignments of onAction (the closure is held
by a strong associated object), so a wrapper can still call through after the control's onAction is
overwritten.Mirrors OnActionExtensionTests.swift 1:1.
onAction == nil.target and action.target, action, and the closure.target.perform(action, with: control)) reaches the stored closure through SelectorWrapper.callClosure, with the sender forwarded.original?(c) runs both the wrapper and the captured original.Preferences.original still fires after onAction is reassigned many times (no premature release).