什么时候在Swift中使用@objc? [英] When to use @objc in Swift?
问题描述
在Swift中,我看到一些类似的方法:
In Swift, I see some methods like:
@objc private func doubleTapGestureRecognized(recognizer: UITapGestureRecognizer)
我想知道何时使用@objc?我读了一些文档,但他们说要在Objective-C中调用它时,应添加@objc标志
I was wondering, when to use @objc? I read some documents, but they are saying when you want it to be callable in Objective-C, you should add @objc flag
但是,这是Swift中的私有函数,@ obj的作用是什么?
However, this is a private function in Swift, what does the @obj do?
推荐答案
private表示仅在Swift中可见. 因此使用@objc在Objective-C中可见. 如果您有可以快速选择私有功能的功能,则为必填项.
private mean it visible only in Swift. so use @objc to visible in Objective-C. If you have a func to selector a private func in swift, it is required.
@objc属性使您的Swift API在Objective-C和Objective-C运行时中可用.
The @objc attribute makes your Swift API available in Objective-C and the Objective-C runtime.
这篇关于什么时候在Swift中使用@objc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!