Im trying to conditionally include a delegate

I want to conditionally add a delegate for only iOS (not VisionOS) This is where I assign a ViewController that is a delegate. The Framework below is not compatible with VisionOS. I get an error when I compile: "cannot assign ViewController to delegate FrameworkDelegate"

#if os(iOS)
    //for iOS target use VC for delegate assignment
    self.framework.delegate = delVC
#endif

Here is where I have the ViewController header (ViewController.h)

#if OS_TARGET_IOS

#import "MyProject-Swift.h"
//for iOS target use delegate
@interface AttendanceViewController : UIViewController<FrameworkDelegate>

#else
//for VisioOS target, no delegate
@interface AttendanceViewController : UIViewController

#endif

Even though I specify in both places that the framework is used for iOS, the compiler does not allow it to compile. Does objective-c complicate the matter? I like my library function in Swift!

Replies

Hopefully this fixed it by using optional binding of the Frameworks protocol type.

    @objc func setDelegate(vc: ViewController?)  {
        if let delVC = vc as? FrameworkDelegate {

            self.framework = Framework()
            self.framework.delegate = delVC
            
            self.start()
        } 
    }