1

I have a class hierarchy like this: MySwiftSubViewController -> ViewController -> UIViewController. Here is the code:

#import <UIKit/UIKit.h>

@class SwiftClassFromPackage;

@interface ViewController : UIViewController
@property (nonatomic, strong) SwiftClassFromPackage* _Nullable someSwiftObjectFromPackage;

@end

This class is using a type from an SwiftPackage for a property. Inside the Objective-C class it seems to be fine:

#import "ViewController.h"
@import MyPackage;

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    _someSwiftObjectFromPackage = [[SwiftClassFromPackage alloc] init];
}
@end

But in the Swift subclass it got an compile error when I use this property like this:

import UIKit
import MyPackage

class MySwiftSubViewController: ViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        print("\(self.someSwiftObjectFromPackage.text)") 
        // Value of type 'MySwiftSubViewController' has no member 'someSwiftObjectFromPackage'
    }
}

When I use this SwiftClassFromPackage class outside the package then it is working but not when it is coming from an package.

Any suggestions why this is not working?

iljer
  • 564
  • 6
  • 9
  • Interface of Objective-C class that needs to be visible by swift must be imported in the bridging header file in your project. On the other direction, Swift class are automatically converted to Objective-C interface in the Project-Swift.h file which must be included in Objective-C or prefix header. – Ptit Xav Mar 25 '23 at 19:23
  • Thank you for your response. These things seems to be fine. My Objective-C class is visible to the Swift class and vice versa. Also the class from the Swift Package is visible to both. What is causing problems is the inheritance from Objective-C to Swift. The sub class in Swift will not get functions or properties from the Objective-C class when it is using the class from the Swift Package as type. – iljer Mar 27 '23 at 07:34

0 Answers0