Enable class extension only if iOS11 is available

I am trying to extend a class written in Obj-C and include an extension written in Swift, which makes it compatible with UIDropInteractionDelegate, for example:

@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))
    }
}

My problem is that the file Project_Name-Swift.hcontains 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 complains that the interface in this file is partial.

'UIDropInteractionDelegate' is partial: introduced in iOS 11.0

I assumed that the inclusion @available(iOS 11.0, *)would lead to a creation SWIFT_AVAILABILITY(ios,introduced=11.0)that would encapsulate the entire interface, but I was wrong.

Is there any way to fix this?

UPDATE


I applied a toy example.

Here is the ViewController toy:

enter image description here

Here is a quick extension:

enter image description here

And here is the generated dnd_toy-Swift.h file.

enter image description here

, , , .

, ?

+6
3

Xcode 9 beta 4 , @available . , @available .

+4

ObjC API_AVAILABLE(ios(11.0)) . :

- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0))
{
     ... function implementation ...
}
+8

, , .

, () iOS 11, , -. iOS 11.

, , iOS 11, , iOS 10 . new (to obj-c) @available API.

if (@available(iOS 11, *)) {
    [self setupDropInteractions];
}

Xcode 8, #available, Swift.

Update

, . , , , , .

2 , , , , .

objc my_project-Swift.h:

@interface NoteEditViewController (SWIFT_EXTENSION(conditional_class_declaration)) <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

1: objc

enter image description here

2: ,

enter image description here

, , .

2: ,

, , Xcode 8.3, 9. , . CLANG_WARN_UNGUARDED_AVAILABILITY, , , Xcode 9.

:

  • YES .pbxproject enter image description here

:

  • YES_AGGRESSIVE .pbxproject enter image description here

WWDC2017 - LLVM, , , . , clang ( ). , , iOS 10. , "", API- IOS 11.

+6

All Articles