You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, I am happy to know this is still alive, as it is awesome!
Low level, but awesome.
My question is, what is the approach to test respondsToSelector: ?
I ask because the most common, and tragic mistake I have hit again and again is the stringly selector calling and missing a trailing colon on a selector that takes an argument.
In pure Objective-C this generally isn't a problem because Xcode corrects it most of the time (it is rare to have valid selectors with and without the colon because even Apple/NeXT learned that was troublesome) also because the exeption thrown will have the selector in the stack trace.
Arguably, even the Objective-C runtime could be more forthright about that, but it is also possible the object or its type are not what one expected.
So, I'd like to add this in for debugging (and potentially raise a Pull Request for making it a debug action to check for respondsToSelector: before each call.)
I think I got it, for anyone else's future reference, or correction if wrong.
I was trying to figure out which name of finishedLaunching BOOL property of an NSRunningApplication instance to use.
(of course it responds to both... ugh.)
But this syntax for calling respondsToSelector: seems to work.
In particular it seems one needs to import Pointer from jna
importcom.sun.jna.Pointer;
// code that creates an NSRunningApplication instance named runningApp goes here...String[] selectors = { "isFinishedLaunching", "finishedLaunching" };
for (StringaSelector : selectors) {
PointerselPointer = ca.weblite.objc.Runtime.INSTANCE.sel_getUid(aSelector);
System.out.println(String.format("runningApp respondsToSelector \"%s\" ? %b",
aSelector,
runningApp.send("respondsToSelector:", selPointer)));
}
Have you had continued success with this method? I've been trying to work out the right selector I need (not an ObjC coder...) and I just get true from everything.
No.
I cannot get this to line up with my results in Xcode for the same class and methods.
I still do not know how to properly check respondsToSelector: with this bridge.
@uchuugaka@shannah any blog post or tutorials available for a beginner developer to run this test code? Add ObjCBridge.jar and jna.jar to your classpath means macOS java classpath via terminal or via xcode?
There is no need for XCode. ObjCBridge.jar and jna.jar go in your java classpath (e.g. in terminal, or in your IDE, however you build your java project). libjcocoa.dylib needs to be in your java library path.
Thanks, I will stop bugging you here, are you available in any of the slackgroup for asking more beginner level questions? (email also works if you don't mind)
Activity
uchuugaka commentedon Apr 3, 2018
I think I got it, for anyone else's future reference, or correction if wrong.
I was trying to figure out which name of finishedLaunching BOOL property of an NSRunningApplication instance to use.
(of course it responds to both... ugh.)
But this syntax for calling
respondsToSelector:seems to work.In particular it seems one needs to import
Pointerfromjnaind1go commentedon Apr 11, 2018
Have you had continued success with this method? I've been trying to work out the right selector I need (not an ObjC coder...) and I just get
truefrom everything.uchuugaka commentedon Apr 12, 2018
No.
I cannot get this to line up with my results in Xcode for the same class and methods.
I still do not know how to properly check respondsToSelector: with this bridge.
LOG-TAG commentedon Mar 19, 2019
@uchuugaka @shannah any blog post or tutorials available for a beginner developer to run this test code? Add ObjCBridge.jar and jna.jar to your classpath means macOS java classpath via terminal or via xcode?
shannah commentedon Mar 19, 2019
There is no need for XCode. ObjCBridge.jar and jna.jar go in your java classpath (e.g. in terminal, or in your IDE, however you build your java project). libjcocoa.dylib needs to be in your java library path.
LOG-TAG commentedon Mar 21, 2019
Thanks, I will stop bugging you here, are you available in any of the slackgroup for asking more beginner level questions? (email also works if you don't mind)
mojo2012 commentedon Jul 29, 2019
@uchuugaka
have you tried something like this:
It returns a Pointer
native@0x1(I guess this means true?)