ios – Swift:CGPathRelease和ARC

前端之家收集整理的这篇文章主要介绍了ios – Swift:CGPathRelease和ARC前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
刚刚更新到 Xcode Beta 4,并注意到以下编译器错误,我的代码如下:
var path = CGPathCreateMutable()
...
CGPathRelease(path)

‘CGPathRelease’ is unavailable: Core Foundation objects are
automatically memory managed

所以,我只是删除我的发布呼叫,一切都应该没问题?还是有更多我想念的东西? ARC有什么特殊情况需要注意吗?

解决方法

使用Swift与Cocoa和Objective-C的 Working with Cocoa Data Types部分说(强调我的):

Core Foundation objects returned from annotated APIs are automatically memory managed in Swift—you do not need to invoke the CFRetain,CFRelease,or CFAutorelease functions yourself. If you return Core Foundation objects from your own C functions and Objective-C methods,annotate them with either CF_RETURNS_RETAINED or CF_RETURNS_NOT_RETAINED.

When Swift imports APIs that have not been annotated,the compiler cannot automatically memory manage the returned Core Foundation objects. Swift wraps these returned Core Foundation objects in an Unmanaged<T> structure.

所以,是的,除非你有一个非托管结构,这是正确的,你不必担心手动释放对象.

原文链接:https://www.f2er.com/iOS/329314.html

猜你在找的iOS相关文章