Xojo and Xcode Cocoa MacOS Library

Can someone smarter than me help?

I’m familiar with both Xojo and Xcode, but don’t know how to make an Xcode Cocoa Library that I can call from Xojo.

I’m looking for an example Xcode Library project (MacOS with Cocoa)

That would contain something like

.h file
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject

@property (nonatomic) BOOL window;
@property (nonatomic) NSString *str;

- (void) suboutput:(NSString *)newOutput;
@end

.m file
#import <Cocoa/Cocoa.h>
@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
	// Insert code here to initialize your application
}
- (Int64) suboutput:(NSString *)mystring
 {
    NSLog (@"Testing");
    return 1
}

and that I can call from Xojo using something like this:

CONST dylibLocation = "@executable_path/Users/Test//libtest.dylib"

Declare Function suboutput lib dylibLocation () as Int64

dim test as Integer = suboutput()

I don’t know if these examples are the right combination or proper code, but if I can get this far I can figure the rest out. Does anyone have an example that I can try?

Thank you. Jordan

I’m not the guru you’re looking for, but offhand what you describe sounds rather like a plugin (some already exist for the examples you give.) Perhaps the Plugin SDK documentation would be a good reference.

The only way I have done this is to use the macOS Plug-In solution, which appears to be deprecated now, as Xcode no longer offers a template (great).

You then typically use [NSBundle bundleWithURL:] and store the reference. Don’t forget to retain it or use the Init version of the method, and release it when you’re done.

Rather than declare directly into the plugin. I’ll be honest and say that I don’t even know if you can point to a library using @executable_path or @rPath from a Xojo declare. Hopefully @Greg_O_Lone can confirm if this would work or not, I’ve not tried it.

Instead I use objc_msgSend to send a message to the bundle. I’d have to look it up exactly how I do it because I don’t recall off the top of my head.

Or you could Ask @Christian_Schmitz as Xojo plugins are his thing.

Been banging my head against a wall for a few days…

Tried following this

Could someone please give this a shot? I’d like to know if it’s me or something wrong with the instructions.

J

Hi @Jordan_Davis,

I think that the examples under Xojo’s Extras > PluginsSDK folder are an excellent starter (even with examples ready to compile and go!)

Once you have played with any of these (Module, Class…) you can even make your Xcode template based on any of that projects.

Javier, Thank you for pointing that out. Will have a look! :wink: