gpt4 book ai didi

ios - iOS中 block (Objective-C)和闭包(Swift)之间的区别

转载 作者:IT老高 更新时间:2023-10-28 11:40:26 25 4
gpt4 key购买 nike

在教程中写到在功能上两者都是相同的,即使闭包比阻塞更容易,并且它避免了 block 和内存管理的复杂性,我已经阅读了许多教程,但除了这些我没有得到 swift 之间的区别“闭包”和Objective-C“ block ”。

最佳答案

摘自:Apple Inc.“将 Swift 与 Cocoa 和 Objective-C 结合使用”。 iBooks:

“Swift closures and Objective-C blocks are compatible, so you can pass Swift closures to Objective-C methods that expect blocks. Swift closures and functions have the same type, so you can even pass the name of a Swift function.

Closures have similar capture semantics as blocks but differ in one key way: Variables are mutable rather than copied. In other words, the behavior of __block in Objective-C is the default behavior for variables in Swift.”

关于ios - iOS中 block (Objective-C)和闭包(Swift)之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26374792/

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