0

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
ed_is_my_name
  • 601
  • 3
  • 9
  • 24
  • possible duplicate of [NSString to CFStringRef and CFStringRef to NSString in ARC?](http://stackoverflow.com/questions/17227348/nsstring-to-cfstringref-and-cfstringref-to-nsstring-in-arc) – luk2302 Apr 14 '15 at 20:43
  • PLEASE just google your problem, is that sooo hard? – luk2302 Apr 14 '15 at 20:43
  • @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 Apr 15 '15 at 14:59

1 Answers1

4

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;
Paulw11
  • 108,386
  • 14
  • 159
  • 186