简体   繁体   English

免费电话桥

[英]Toll free bridges

As a newcomer to iPhone development and Objective-C in general over the last few weeks I have come across numerous mentions of 'Toll free bridges' between CF and NS frameworks. 在过去的几周里,作为iPhone开发和Objective-C的新手,我在CF和NS框架之间遇到了许多关于“免费桥接”的提及。

One particular example would be CFStream and NSStream. 一个特定的例子是CFStream和NSStream。

Does a resource exists documenting all of these bridges and how to use them ? 是否存在记录所有这些桥梁以及如何使用它们的资源? Is it just as simple as casting from an object of one type to another ? 它是否就像从一种类型的对象转换到另一种类型一样简单?

I ask as at the moment I am using NSStream calls that are not stricly allowed within the iPhone SDK and understand that I should be using CFStream calls. 我问,目前我正在使用iPhone SDK中不严格允许的NSStream调用,并了解我应该使用CFStream调用。

EDIT: A useful article about how TFB works 编辑:关于TFB如何工作的有用文章

Toll-free bridging means that the data structures are interchangeable. 免费桥接意味着数据结构是可互换的。 It is just as simple as casting — that's the "toll-free" part. 它就像铸造一样简单 - 这就是“免费”部分。 Anyplace you can use the type on one side of the bridge, you can use the other. 您可以在桥的一侧使用该类型的任何地方,您可以使用另一个。 So, for example, you can create a CFString and then send NSString messages to it, or you can create an NSArray and pass the array to CFArray functions. 因此,例如,您可以创建CFString然后向其发送NSString消息,或者您可以创建NSArray并将该数组传递给CFArray函数。

Apple keeps a list of the supported toll-free bridged types on its site. Apple在其网站上列出了受支持的免费桥接类型列表

Toll-free-bridging, although a funny name, is a very cool feature of the CoreFoundation classes. 免费桥接,虽然有趣的名称,是CoreFoundation类的一个非常酷的功能。 Essentially it boils down to the fact that you can cast between CoreFoundation and NextStep classes of the same name (CFString<->NSString, CFData<->NSData, CFDictionary<->NSDictionary... just to name some of the most commonly used.) 从本质上讲,它可以归结为这样一个事实:你可以在CoreFoundation和同名的NextStep类之间进行转换(CFString < - > NSString,CFData < - > NSData,CFDictionary < - > NSDictionary ...只是为了说出一些最常用的。)

|K< | K <

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM