Page 1 of 1

[Q] unable to bind to foreign handler

Posted: Sat Nov 18, 2017 10:17 am
by shaosean

Code: Select all

library tk.shaosean.library.mac.test

use com.livecode.foreign
use com.livecode.objc

metadata version is "1.0.0"
metadata author is "shaosean.tk"
metadata title is "test"

---------------------

private foreign handler NSUserNotificationAlloc() returns ObjcRetainedId binds to "objc:NSUserNotification.+alloc"
private foreign handler NSUserNotificationInit(in Obj as ObjcId) returns ObjcId binds to "objc:NSUserNotification.-init"
private foreign handler NSUserNotificationSetTitle(in Obj as ObjcId, in Title as ObjcId) returns nothing binds to "objc:NSUserNotification.-setTitle:"

---------------------


public handler Test() returns nothing
	if the operating system is "mac" then
		unsafe
			variable aNSUserNotification as ObjcObject
			put NSUserNotificationAlloc() into aNSUserNotification
			put NSUserNotificationInit(aNSUserNotification) into aNSUserNotification

			NSUserNotificationSetTitle(aNSUserNotification, StringToNSString("hello"))
		end unsafe
	end if
end handler


end library

Code: Select all

--executing at 4:09:44 AM
--LCB Error	Unable to bind foreign handler tk.shaosean.library.mac.test.NSUserNotificationSetTitle
--Object	Button
--LCB File	test.lcb
--LCB Line	26
From everything I can tell, my code is correct, but for some reason the setTitle: is not binding.. I looked at the code from the MacButton.lcb that ships with LiveCode, and other than the class, the code is identical, but their binding works..

Is this a bug? Is this PEBCAK error? Is it something else?

Re: [Q] unable to bind to foreign handler

Posted: Mon Dec 04, 2017 2:19 pm
by livecodeali
Bug report, for reference: http://quality.livecode.com/show_bug.cgi?id=20733

Further to my explanation on the above report, you should be able to work around the issue using setValue:forKey:

Code: Select all

private foreign handler NSUserNotificationSetProperty(in Obj as ObjcId, in pValue as ObjcId, in pProp as ObjcId) returns nothing binds to "objc:NSUserNotification.-setValue:forKey:"

NSUserNotificationSetProperty(aNSUserNotification, StringToNSString("hello"), StringToNSString("title"))

Re: [Q] unable to bind to foreign handler

Posted: Mon Dec 04, 2017 3:20 pm
by shaosean
Nice, I'll give that a try. I see that Mark W did a fix for other classes, that work the same.

Thanks for the quick response to this. :-)