-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
SwiftPamphletApp/Resource/Guide/Widget小部件/Widget访问SwiftData(ap).md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
Wdiget target 访问主应用 target 的 SwiftData 数据步骤如下: | ||
|
||
- 对主应用和 Widget 的 target 中的 Signing & Capabilities 都添加 App Groups,并创建一个新组,名字相同。 | ||
- SwiftData 的模型同时在主应用和 Widget 的 target 中。 | ||
- StaticConfiguration 或 AppIntentConfiguration 中添加 `modelContainer()` 修饰符,让 SwiftData 的容器可用。 | ||
|
||
SwiftData 数据变化后,小组件能够及时更新的方法 | ||
|
||
```swift | ||
WidgetCenter.shared.reloadAllTimelines() | ||
``` |