仅当iOS11可用时才包括课程的扩展名 [英] Include an extension for a class only if iOS11 is available

查看:134
本文介绍了仅当iOS11可用时才包括课程的扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试扩展用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中引入

'UIDropInteractionDelegate' is partial: introduced in 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?

推荐答案

如果将@available添加到每种方法,则将构建Xcode 9 beta 4。如果仅在扩展级别添加@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可用时才包括课程的扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆