刚刚更新到
Xcode Beta 4,并注意到以下编译器错误,我的代码如下:
var path = CGPathCreateMutable() ... CGPathRelease(path)
@H_301_5@‘CGPathRelease’ is unavailable: Core Foundation objects are@H_301_5@所以,我只是删除我的发布呼叫,一切都应该没问题?还是有更多我想念的东西? ARC有什么特殊情况需要注意吗?
automatically memory managed
解决方法
使用Swift与Cocoa和Objective-C的
Working with Cocoa Data Types部分说(强调我的):
@H_301_5@Core Foundation objects returned from annotated APIs are automatically memory managed in Swift—you do not need to invoke the@H_301_5@所以,是的,除非你有一个非托管结构,这是正确的,你不必担心手动释放对象.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
. @H_301_5@… @H_301_5@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 anUnmanaged<T>
structure.