0
votes

I'm just trying to cast NSString* to CTStringRef*

    NSString *foobar = @"foobar";
    CFStringRef *tmp = (__bridge_retained CFStringRef*)foobar;

Can someone help with this error? "Incompatible types casting 'NSString *' to 'CTStringRef *' (aka const struct __CFString **)with a __bridge_retained cast"

I've tried with simply __bridge and it don't work either. From the documentation, I think the _retained is the right type I need. Thanks.

1
PLEASE just google your problem, is that sooo hard? - luk2302
@luk2303, well it's not too hard. I did see that other post, but the solution in that thread is not working for me. Let me explain: I knew that removing the * would resolve the error, but a warning remains...therefore, I'm likely doing something else wrong. Looking for help. - ed_is_my_name

1 Answers

4
votes

If you look closely at the error message you will see what your problem is. The hint is in this part -

__CFString **

Notice the two * - This means that you are trying to cast to a pointer to a pointer, or in other words a reference to a reference. CTStringRef is already a reference, as implied by the 'Ref' part of the name, so you don't need the * in (__bridge_retained CFStringRef*)

Your code should read

NSString *foobar = @"foobar";
CFStringRef tmp = (__bridge_retained CFStringRef)foobar;