I'm just starting to learn iOS app development and I'm currently using SwiftData. The main app is working fine, and now I've added a Widget to use data from the main app. I've already enabled App Groups and want to reference the shared model entities from the main app, but I'm getting an error saying "can't find type in scope." What additional configurations do I need to make in order to properly reference the same entities? I've seen many example codes that have a "Shared" folder, but even after creating one and moving the files into it, I'm still unable to use them properly. I must be missing some configuration, right?
Also, there's another issue: when debugging the Widget, I keep getting the following error. What could be causing this?
SendProcessControlEvent:toPid: encountered an error: Error Domain=com.apple.dt.deviceprocesscontrolservice Code=8 "Failed to show Widget 'XXXX-Widget' error: Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.springboard" failed."
My guess is that you probably haven't added the files that contain SwiftData model classes to your widget target. You can confirm with the following steps:
- In Xcode's Project Navigator, select the file that contains the type.
- Find the Target Membership section in Xcode's File Inspector on the right, and check if both your main app and widget targets are there.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.