0

I am building an objective C framework that uses swift for a UI screen. I can not access an objective c header from my SwiftUI View file.

MyApi.h

#ifndef MyApi_h
#define MyApi_h
#import <UIKit/UIKit.h>

@interface MyApi : NSObject

- (NSDictionary *)getProfile;
#endif

ProfileView.swift

import SwiftUI

@available(iOS 13.0.0, *)
struct ProfileView: View {
    var body: some View {
        var instanceOfMyApi = MyApi()
        var myJson = MyApi.getProfile()
        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
    }
    
}

struct ProfileView_Previews: PreviewProvider {
    static var previews: some View {
        ProfileView()
    }
}

MyApi.h is public of course.

I keep getting error: Cannot find 'MyApi' in scope.

I can not use a bridging header as it is a framework.

Any thoughts?

billysk
  • 137
  • 1
  • 13
  • 1
    Does this help? [Xcode 6 / Beta 4: using bridging headers with framework targets is unsupported](https://stackoverflow.com/questions/24875745/xcode-6-beta-4-using-bridging-headers-with-framework-targets-is-unsupported) Specifically, in a new Objective-C Framework project, I added an Objective-C class and a Swift class, made the Objective-C header public, and imported it from the framework umbrella header, and the Swift class recognized it. – Itai Ferber Jan 14 '22 at 16:34
  • (The above comment assumes that you intend for the `MyApi.h` header to be public — if it can't be made public, then the second answer to the above question might be of help: [making internal headers accessible to Swift using a private module map](https://stackoverflow.com/a/47473572/169394)) – Itai Ferber Jan 14 '22 at 16:35
  • Have you imported framework with `MyApi` class? – Cy-4AH Jan 16 '22 at 12:43

0 Answers0