I'm trying to export an iOS Widget Extension as a CocoaPods library. Since adding a widget extension requires a target, I should create the target manually in the host project, then transfer the widget files to the repository. Therefore, the library will just vend raw files and not act as an extension.
First question: Am I right? Is there a way to save the whole extension in the repository?
Now the Podfile is:
target 'Example' do use_frameworks! # I need to create a `MyWidget` widget first target 'MyWidgetExtension' do inherit! :search_paths pod 'WidgetIOSSDK', :path => '../' endend
In the widget entry point (MyWidgetBundle.swift
), I use the widget from the library:
import WidgetIOSSDK@mainstruct MyWidgetBundle: WidgetBundle { var body: some Widget { MyWidget2() }}
Build and run, the widget appears on the desktop. Then here is question 2:
- I can't preview the SwiftUI if the file is not in the host project. (picture 1 below)
- Even if in the host project I create a blank SwiftUI file and in the preview section I use the view from the pod library, it doesn't work either.(picture 2 below)
Is there a way to preview in other location?