Splitting the Widget Code
I started working on my first widget this week, and ran into an weird problem. After creating a new Widget Extension target I tried to split up the AppWidget.swift
file into multiple files, one each for the TimelineProvider, Widget, and View. When I did, I ran into this error:
1
2
SchemeBuildError: Failed to build the scheme “AppWidgetExtension”
reference to invalid associated type 'Entry' of type 'Provider'
I came across a post in the developer forum about a similar issue, but it had no solution. Unfortunately, I was unable to really find any other reference to it. I decided to ask around in the various Discord and Slack servers I am in and was able to get an answer from Geoff Pado (AKA Cocoatype). He suggested that I change Entry
in
1
2
3
func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> Void) {
.....
}
to SimpleEntry
like the placeholder
and getTimeline
functions have and that seemed to work.
1
2
3
func getTimeline(in context: Context, completion: @escaping (Timeline<SimpleEntry>) -> Void) {
.....
}
This allowed me to split my files up so it was easier to edit them.