轉換工程到ARC ,結果這行代碼報錯:
_font = CTFontCreateWithName((CFStringRef)_fontName, fontSize, NULL);
其中 _fontName是NSString,錯誤信息是:
Cast of Objective-C pointer type 'NSString *' to C pointer type 'CFStringRef' (aka 'const struct __CFString *') requires a bridged cast
我找到了兩種解決方法:
第一種:Use __bridge to convert directly (no change in ownership)
第二種:Use CFBridgingRetain call to make an ARC object available as a +1 'CFStringRef' (aka 'const struct __CFString *')
不知道那種比較好?
沒必要修改_fontName的所屬關系,用這個就行
_font = CTFontCreateWithName((__bridge CFStringRef)_fontName, fontSize, NULL);