Yes, that's nice, clean approach, and will do what I need.

Thanks!
-Carl


> On Nov 13, 2020, at 11:42 AM, Martin Wierschin <mar...@nisus.com> wrote:
> 
> A nice way to do this is to have a bridge header file that only declares C 
> functions. The corresponding .m source code file will have C functions that 
> natively call Objective-C methods. This same header can be included in .c 
> files without any trouble, letting them have access to Obj-C code via the 
> bridge's C functions.
> 
> Basically structure your files something like this:
> 
> **************** MyBridge.h
> extern void DoObjectiveCStuff();
> 
> **************** MyBridge.m
> #import <Foundation/Foundation.h>
> 
> void DoObjectiveCStuff()
> {
>       NSLog(@"Hooray, calling Obj-C methods...");
>       [NSArray arrayWithCapacity:32];
> }
> 
> **************** pure.c
> #include "MyBridge.h"
> 
> void RegularFunction()
> {
>       DoObjectiveCStuff();
> }
> 
> I hope that helps!
> 
> ~Martin Wierschin
> 
> 
>> On Nov 13, 2020, at 11:16 AM, Carl Hoefs via Cocoa-dev 
>> <cocoa-dev@lists.apple.com> wrote:
>> 
>> I have built an ObjC/Cocoa/Foundation library.dylib; it works well when 
>> linked with ObjC apps. 
>> 
>> But now I need to link a C program against that library. How do I invoke the 
>> ObjC library methods from a C program? (I know I can add C function entry 
>> points to the library, but how do they invoke the internal ObjC library 
>> methods?)
>> 
>> -Carl
> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to