【发布时间】:2013-01-15 08:40:19
【问题描述】:
CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)boldSystemFont.fontName, boldSystemFont.pointSize, NULL);
NSRange rangeHighlight = NSMakeRange(range.location, substringToHighlight.length);
if (font) {
[mutableAttributedString addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)font range:rangeHighlight];
CFRelease(font); //Is this still necessary?
}
我从https://github.com/mattt/TTTAttributedLabel复制并粘贴这段代码
CTFontRef font = CTFontCreateWithName((CFStringRef)boldSystemFont.fontName, boldSystemFont.pointSize, NULL);
if (font) {
[mutableAttributedString addAttribute:(NSString *)kCTFontAttributeName value:(id)font range:boldRange];
[mutableAttributedString addAttribute:@"TTTStrikeOutAttribute" value:[NSNumber numberWithBool:YES] range:strikeRange];
CFRelease(font);
}
当我这样做时,我得到一个错误,说我必须使用关键字 __bridge。它是什么?我把它和编译错误停止。但后来我想知道我是否还需要使用 CFRelease(font)
另外
- 什么是 CFRelease 中的 CF?
- 什么是__bridge?
- 我应该在使用 __bridge 后执行 CFRelease(font) 吗?
- 在哪里可以了解更多信息?
【问题讨论】:
标签: objective-c xcode4.5