刚刚更新到 Xcode Beta 4,并注意到我的代码出现以下编译器错误:
var path = CGPathCreateMutable()
...
CGPathRelease(path)
'CGPathRelease' is unavailable: Core Foundation objects are automatically memory managed
那么我是否只需删除我的发布调用,一切就应该没问题了?还是我还缺少什么?对于 ARC,我应该注意什么特殊情况吗?
最佳答案
Working with Cocoa Data Types 使用 Swift 与 Cocoa 和 Objective-C 部分说(强调我的):
Core Foundation objects returned from annotated APIs are automatically memory managed in Swift—you do not need to invoke the
CFRetain
,CFRelease
, orCFAutorelease
functions yourself. If you return Core Foundation objects from your own C functions and Objective-C methods, annotate them with eitherCF_RETURNS_RETAINED
orCF_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.
所以是的,除非你有 Unmanaged
struct,这是正确的,您不必担心手动释放该对象。
关于ios - Swift:CGPathRelease 和 ARC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37430172/