NSString & CFStringRef

来源:互联网 发布:unity3d 5.x pdf 编辑:程序博客网 时间:2024/05/18 01:24

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.


原创粉丝点击