Hello,
as the title says, I need to call an AppleScript method from an Objective-C class. This is the Objective-C class:
But I get the error Use of undeclared identifier ‘MSItems’. I even tried importing the MSItems class but nothing.
How can I do this?
Thanks!
Add an interface for your class after the #import line:
@interface MSItems: NSObject
// declare your handlers here as methods, for example:
+ (void)myMethod;
@end
And where do I define that method? Shall I create an implementation file?
In your AS file for class MSItems:
on myMethod()
-- whatever
end
In this way the App fails to build and I get the error:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_MSItems", referenced from:
objc-class-ref in MSTabView.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I’ve read somewhere that this means something is missing.
Sorry, you also need:
@class NSItems;
before the @interface.
In fact I tend to put it in the header file, along with a property that I then connect to a blue-cube instance of the class. Then I just call instance methods rather than class methods – I’ve found them more reliable anyway.
Thanks, but I’m still getting that error…
Because in the Objective-C file +myMethod is declared as a class method, perhaps shall I define it in applescript in a different way? And in the applescript file as property parent shall I leave “NSObject”?
You can make it an instance method (change the + to -). Or you can try referring to the class like this:
NSClassFromString(@"MSItems")
Thanks Shane, it worked! I referred to the class In that way, leaving the method a class method!