gpt4 book ai didi

ios - Swift:CGPathRelease 和 ARC

转载 作者:IT王子 更新时间:2023-10-29 05:47:08 27 4
gpt4 key购买 nike

刚更新到 Xcode Beta 4,发现我的代码出现以下编译器错误:

var path = CGPathCreateMutable()
...
CGPathRelease(path)

'CGPathRelease' is unavailable: Core Foundation objects are automatically memory managed

那么我是否只是简单地删除我的发布调用,一切都应该没问题?或者还有什么我想念的吗?对于 ARC,有什么我应该注意的特殊情况吗?

最佳答案

Working with Cocoa Data Types Using Swift with Cocoa and Objective-C 部分说(强调我的):

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.

所以是的,除非你有 Unmanaged结构,这是正确的,您不必担心手动释放对象。

关于ios - Swift:CGPathRelease 和 ARC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24900595/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com