Swift - adding controls to a TabPanel

I have dozens of subclassed controls

class C1 : NSView {
vareventDelegate : myDelegate
... other stuff ...

class S1 : NSSlider  {
var eventDelegate : myDelegate
... other stuff ...

Adding these to the base window works fine using a method like this

public func addToView(_ parent:NSView?) {
  self.eventDelegate  = parent!.window as? dsCONTROLDELEGATE

HOWEVER adding them to a TabPanel/Pagepanel is more difficult
adding the control itself is easy

class myTab : NSTabView {
public func addToPanel(panel:Int,control:NSView) {
   self.tabViewItem(at: panel).view?.addSubview(control)
/* here is where the problem lies
Using NSView allows me to add the control to the view
BUT, it has no idea what "eventdelegate" is
and using **let temp: AnyClass? = control.superclass** doesn't help
basically this routine needs to accept ANY control type and know it has a eventDelegate parameter
   ???.eventDelegate  = self.window as? dsCONTROLDELEGATE
var tView : myTab() 
var myC1 : C1()
var myS1 : S1()


note ALL controls end up pointing their eventdelegate back to the NSWindow that ultimately hosts the control. So a control on a TabPanel, does not delegate to the panel, but to the window itself

I turned the problem around …

public func addToPanel(parent:NSTabView,panel:Int) {
		parent.tabViewItem(at: panel).view?.addSubview(self)
		self.eventDelegate  = parent.window as? dsCONTROLDELEGATE

	public func addToView(_ parent:dsVIEW?) {
		self.eventDelegate  = parent!.window as? dsCONTROLDELEGATE

	public func addToView(_ parent:dsWINDOW) {
		addToView(parent.contentView! as? dsVIEW)

so now it becomes

c1.addToPanel(parent:tView, panel:0)
1 Like