在一个 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/