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

标签 objective-c swift

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

相关文章:

iphone - 无法在 iOS 5.0 中调整事件指示器的大小?

objective-c - 锁定一个对象不被多个线程访问 - Objective-C

ios - SKReceiptRefreshRequest 每次都询问密码

SwiftUI:无法推断引用成员的上下文基础

swift - 为什么FBSDKGraphRequest(graphPath : "me", parameters : params). start being called only once

ios - pod 安装时出现 LoadError

ios - 当应用程序被杀死时,位置不会在行走时更新

swift - 类型 'Any' 没有下标成员

ios - 在 pageController 中获取可见 View

ios - SWIFT 线程 1 : EXC Bad instruction XCODE IOS