问题描述
我正在尝试扩展一个用 Obj-C 编写的类,并包含一个用 Swift 编写的扩展,使其符合 UIDropInteractionDelegate
,如下所示:
I am trying to extend a class written in Obj-C and include an extension written in Swift that makes it conform to the UIDropInteractionDelegate
, like so:
@available(iOS 11.0, *)
extension NoteEditViewController: UIDropInteractionDelegate {
@available(iOS 11.0, *)
public func dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal {
let operation: UIDropOperation
if session.localDragSession == nil {
operation = .forbidden
} else {
// If a local drag session exists, we only want to move an
// existing item in the pin board to a different location.
operation = .forbidden
}
return UIDropProposal(operation: operation)
}
@objc(setupDropInteractions)
@available(iOS 11.0, *)
func setupDropInteractions() {
// Add drop interaction
self.view.addInteraction(UIDropInteraction(delegate: self))
}
}
我的问题是 Project_Name-Swift.h
文件包含以下无法编译的代码:
My problem is that Project_Name-Swift.h
file contains the following code that will not compile:
@class UIDropInteraction;
@protocol UIDropSession;
@class UIDropProposal;
// This line is causing the issue saying "'UIDropInteractionDelegate' is partial: introduced in iOS 11.0"
@interface NoteEditViewController (SWIFT_EXTENSION(Bloomberg_Professional)) <UIDropInteractionDelegate>
- (UIDropProposal * _Nonnull)dropInteraction:(UIDropInteraction * _Nonnull)interaction sessionDidUpdate:(id <UIDropSession> _Nonnull)session SWIFT_WARN_UNUSED_RESULT SWIFT_AVAILABILITY(ios,introduced=11.0);
- (void)setupDropInteractions SWIFT_AVAILABILITY(ios,introduced=11.0);
@end
编译器抱怨该文件中的接口是部分的.
The compiler is complaining that the interface in that file is partial.
'UIDropInteractionDelegate' 是部分的:在 iOS 11.0 中引入
我假设包含 @available(iOS 11.0, *)
会生成一个 SWIFT_AVAILABILITY(ios,introduced=11.0)
来封装整个接口,但我是错了.
I assumed that including the @available(iOS 11.0, *)
would generate a SWIFT_AVAILABILITY(ios,introduced=11.0)
that would encapsulate the entire interface but I was wrong.
有没有办法解决这个问题?
Is there a way to fix this?
更新
我实现了一个玩具示例.
I implemented a toy example.
这是玩具 ViewController:
Here is the toy ViewController:
这里是快速扩展:
这里是生成的 dnd_toy-Swift.h 文件.
And here is the generated dnd_toy-Swift.h file.
你说得对,它只是一个警告,但我的问题是我们必须将所有警告都视为项目中的错误.
You were right that it is simply a warning but my problem is that we must treat all warnings as errors in our project.
关于如何从这里消除此警告的任何想法?
Any ideas on how to get rid of this warning from here?
推荐答案
Xcode 9 beta 4 将构建,如果 @available 添加到每个方法.如果仅在扩展级别添加 @available,构建仍然会失败.
Xcode 9 beta 4 will build, if @available is added to each method. The build still fails if @available is added only at the extension level.
这篇关于仅当 iOS11 可用时才包含类的扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!