创建自定义 CFType
是否可以创建不是从 CFTypeRef
派生的不透明类型,并且可以使用 CFRetain
/CFRelease
保留/释放?或者如何从 CFType
派生新类型?
Is it possible to create opaque types not derived from CFTypeRef
which can be retained/released with CFRetain
/CFRelease
? Or how do I derive a new type from a CFType
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从来没有这样做过,但使用私有 API 是可能的。它很可能取决于 OS X 的特定点版本,因为 CF 运行时可能会因版本而异。无论如何,CF 是开源的,所以我看了一下 CFRuntime< /a> 确实如此。我很高兴看到苹果提供了一个例子:
I've never done this, but it is possible using private API. In all likelihood it will be dependent on a specific dot release of OS X, since the CF runtime could change from release to release. In any case, CF is open source so I took a look at what CFRuntime does. I was happy to see Apple included an example:
CoreFoundation 本身不提供任何此类机制,但所有 Cocoa 对象都将与 CFRetain 和 CFRelease 一起使用。所以唯一支持的答案是:创建一个基于 Foundation 的类,CoreFoundation 会将其识别为 CFTypeRef。
CoreFoundation itself does not provide any such mechanism, but all Cocoa objects will work with CFRetain and CFRelease. So the only supported answer is: Create a class based on Foundation and CoreFoundation will recognize it as a CFTypeRef.