现在的位置: 首页 > 综合 > 正文

NSString & CFStringRef

2013年08月24日 ⁄ 综合 ⁄ 共 459字 ⁄ 字号 评论关闭

NSString and CFStringRef are "Toll free bridged", meaning that you can simply typecast between them.

For example:

CFStringRef aCFString = (CFStringRef)aNSString;

works perfectly and transparently. Likewise:

NSString *aNSString = (NSString *)aCFString;

works as well. The key thing to note is that CoreFoundation will often return objects with +1 reference counts, meaning that they need to be released (all CF[Type]Create format functions do this).

The nice thing is that in Cocoa you can safely use autorelease or release to free them up.

抱歉!评论已关闭.