Alex,

I’ve worked on a few wrapper libraries, so I have some experience with this.

In your Obj-C wrapper, you would need to create the NSString yourself. So, if 
you have a C function:

char* MyCFunc(void);

The Objective-C wrapper method would do something like:

- (void) myObjcMethod
{
    char* cStr = MyCFunc();
    NSString* objcStr = [[NSString alloc] initWithUTF8String:cStr];

    return objCStr;
}

Depending on the C function implementation, you might have to deal with 
releasing the C string in your wrapper. Also, I assume UTF-8 encoding, which 
may or may not be true.

Hopefully this helps you.

Doug Hill


> On Mar 4, 2016, at 12:07 PM, Alex Zavatone <z...@mac.com> wrote:
> 
> I'm in the middle of some fun where there is a wrapper class to a lib that's 
> written in C and the c function has a char string that I'd like to return 
> back to or somehow pass on to an Cbjective-C class.
> 
> I'm sure there is an established practice for performing this type of task, 
> but while I have the opportunity to do this, I'd like to start be learning 
> the right way to handle this operation.
> 
> I've seen really poor use of a catch all delegate for this approach, but am 
> pretty unsure on viable and safe methods to handle this.
> 
> Any tips to how to handle this?
> 
> Thanks in advance,
> 
> Alex Zavatone



_______________________________________________

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