2

I need to do some graph plotting in my iPad app, so I've followed this tutorial:

http://recycled-parts.blogspot.com/2011/07/setting-up-coreplot-in-xcode-4.html

In which I had to change my C/C++/Objective-C Compiler to LLVM GCC 4.2. (Originally it was Apple LLVM Compiler 3.0).

Now, I'm unable to _bridge cast a CFStringRef into an NSString. I get the following error:

'_bridge' undeclared (first use in a function)

Can anyone help me sort this out?? Thanks.

3
  • 2
    Have you tried __bridge with 2 _?
    – kennytm
    Jan 12, 2012 at 10:42
  • I'll give that a go now. Thanks KennyTM.
    – theDuncs
    Jan 12, 2012 at 11:55
  • Kenny - turns out Justin's answer was correct (however you were correct for spotting the typo). Thanks for your help.
    – theDuncs
    Jan 12, 2012 at 14:51

2 Answers 2

3

The keyword __bridge has two leading underscores.

Guessing at your code this is probably similar to what you want:

CFStringRef cf = CFSTR("test");
NSString *ns = (__bridge_transfer NSString *)cf;

(It is a simple minded example given the constant string)

1
  • CocoaFu - you're absolutely right, I had made a typo and needed a double underscore. That said, its Justin's answer which answers the question correctly. Thanks for your help though. Much appreciated.
    – theDuncs
    Jan 12, 2012 at 14:52
2

CocoaFu spotted one problem.

Another problem is that GCC+LLVM does not support ARC -- only Clang releases since summer 2011 support ARC. Bridged casting complements ARC.

If you need GCC, you will need to add manual reference counting to the program, or you could move things to separate files for your ARC/MRC differences. Or you could use earlier releases of your dependent libraries, if they are the ones which require ARC. Or... (a few more options)

1
  • 1
    Thanks Justin. You da man. I've now removed the 0.9 release of CorePlot (which doesn't support ARC) and used their latest code version which does. Thanks so much.
    – theDuncs
    Jan 12, 2012 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.