I have created objective-c framework and outside xcframwork copied the resources bundles. When adding binary framework in swiftui, how should that bundle be linked or added?

Asked on 09/08/2024

1 search

To link or add a resource bundle from an Objective-C framework to a SwiftUI app, you can take advantage of SwiftUI's interoperability with other frameworks. SwiftUI allows you to incorporate UIKit or AppKit views, which can be useful for accessing resources from an Objective-C framework.

Here are some general steps you might follow:

  1. Include the Framework: Ensure that your Objective-C framework is properly included in your SwiftUI project. This typically involves adding the framework to your project settings under "Linked Frameworks and Libraries."

  2. Access the Bundle: You can access the resource bundle from your Objective-C framework using Bundle in Swift. For example, if your framework is named MyFramework, you can access its bundle like this:

    if let bundleURL = Bundle.main.url(forResource: "MyFramework", withExtension: "bundle"),
       let bundle = Bundle(url: bundleURL) {
        // Use the bundle to access resources
    }
    
  3. Use the Resources: Once you have access to the bundle, you can load resources such as images, strings, or other assets using the appropriate APIs.

For more detailed guidance, you might want to refer to the session on SwiftUI essentials which discusses SDK interoperability and how SwiftUI can work with other frameworks.