Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ComboBox SetDelegate uses TextField's SetDelegte resulting in error #223

Open
corruptmemory opened this issue Oct 6, 2023 · 1 comment
Labels
generation Related to generation toolchain

Comments

@corruptmemory
Copy link
Contributor

Example:

items := []objc.IObject{
    foundation.NewStringWithString("a"),
    foundation.NewStringWithString("b"),
}

cb := appkit.NewComboBox()
cb.AddItemsWithObjectValues(items)

cbd := &appkit.ComboBoxDelegate{}
cb.SetDelegate(cbd)

Will fail at run time because the particular SetDelegate method invoked is this one:

func (t_ TextField) SetDelegate(value PTextFieldDelegate) {
	po0 := objc.WrapAsProtocol("NSTextFieldDelegate", value)
	objc.SetAssociatedObject(t_, objc.AssociationKey("setDelegate"), po0, objc.ASSOCIATION_RETAIN)
	objc.Call[objc.Void](t_, objc.Sel("setDelegate:"), po0)
}

And since we are giving it a ComboBoxDelegate instead of a TextFieldDelegate, the reflective type check fails.

I've built a work-around for this:

func setComboBoxDelegate(cb appkit.ComboBox, value appkit.PComboBoxDelegate) {
	po0 := objc.WrapAsProtocol("NSComboBoxDelegate", value)
	objc.SetAssociatedObject(cb, objc.AssociationKey("setDelegate"), po0, objc.ASSOCIATION_RETAIN)
	objc.Call[objc.Void](cb, objc.Sel("setDelegate:"), po0)
}

But needless to say, the current behavior isn't what a user would expect.

@progrium
Copy link
Owner

progrium commented Nov 7, 2023

It is possible that generation would make a SetDelegate for ComboBox and skips it because it already exists in TextField, so that would be a generation bug. And your workaround is fine, but there is also always a generic Object version of any method that takes a Protocol interface, in this case SetDelegateObject.

@progrium progrium added the generation Related to generation toolchain label Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generation Related to generation toolchain
Projects
None yet
Development

No branches or pull requests

2 participants