How to prevent extension for export to Swift header for Objective-C?

I made this simple extension in Swift:

extension DispatchQueue { func asyncAfter(delay: TimeInterval, block: @escaping ()->()) { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: block) } } 

In the Project-Swift.h header, it reports an error on this line:

 @interface OS_dispatch_queue (SWIFT_EXTENSION(...)) - (void)asyncAfterDelay:(NSTimeInterval)delay block:(void (^ _Nonnull)(void))block; @end 

Error: Cannot find interface declaration for "OS_dispatch_queue"

Is there a way to prevent the extension from being exported for Objective-C? Or is there a way to fix the error?

+5
source share
2 answers

I know this is not the answer for the tip, but I am facing the same problem using the public extension DispatchQueue: dispatch_once after changing the Swift 3 GCD API

So in my case, using a solution from Vlad helped me avoid this constant problem: fooobar.com/questions/101491 / ...

0
source

You can use @objc before func or method to prevent export for objective-C, as shown below.

 extension DispatchQueue { @objc func asyncAfter(delay: TimeInterval, block: @escaping ()->()) { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: block) } } 
-3
source

Source: https://habr.com/ru/post/1263612/


All Articles