gpt4 book ai didi

objective-c - Swift/ObjectiveC 互操作性 : closure property 'not found on object of type *'

转载 作者:行者123 更新时间:2023-11-28 08:56:42 25 4
gpt4 key购买 nike

在一个 swift 类中,我定义了两个闭包属性,如下所示:

var confirmationHandler: ((address: Address, refinedCoordinate: CLLocationCoordinate2D?) -> Void)?

var anotherHandler: ((address: Address, refinedCoordinate: CLLocationCoordinate2D) -> Void)?

当我尝试从 Objective C 代码设置前者时,出现以下错误:

Property 'confirmationHandler' not found on object of type...

我可以毫不费力地设置后者。这是为什么?

最佳答案

从这里的帖子中得到这个答案: https://stackoverflow.com/a/26366344/1284996

相关段落:

Optionals are a swift specific feature, not available in obj-c. Optional class instances work because a nil optional can be mapped to a nil value, but value types (int, floats, etc.) are not reference types, hence variable of those types don't store a reference, but the value itself.

关于objective-c - Swift/ObjectiveC 互操作性 : closure property 'not found on object of type *' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32871611/

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