2
votes

I am converting one of my projects to ARC and I am getting an error on the following line:

_font = CTFontCreateWithName((CFStringRef)_fontName, fontSize, NULL);

where _fontName is an NSString. The error is:

Cast of Objective-C pointer type 'NSString *' to C pointer type 'CFStringRef' (aka 'const struct __CFString *') requires a bridged cast

I am getting two options on how to fix it from xCode:

Use __bridge to convert directly (no change in ownership)

or

Use CFBridgingRetain call to make an ARC object available as a +1 'CFStringRef' (aka 'const struct __CFString *')

Which would be the better option? I'm thinking the first choice because I'm guessing the CoreText method will retain it. But then again, just want to make sure I'm not discounting something with ARC.

1
rmaddy's answer is correct. As a further reference: stackoverflow.com/questions/17227348/…Gabriele Petronella
@GabrielePetronella - thanksSer Pounce

1 Answers

3
votes

You have no need to transfer ownership of the _fontName reference so you should use:

_font = CTFontCreateWithName((__bridge CFStringRef)_fontName, fontSize, NULL);