diff --git a/JustOneThing.xcodeproj/project.pbxproj b/JustOneThing.xcodeproj/project.pbxproj index 27272db..61fb484 100644 --- a/JustOneThing.xcodeproj/project.pbxproj +++ b/JustOneThing.xcodeproj/project.pbxproj @@ -37,6 +37,9 @@ 5493A81B2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5493A81A2A471E36001EBA08 /* JustOneThingProvider.swift */; }; 5493A81C2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5493A81A2A471E36001EBA08 /* JustOneThingProvider.swift */; }; 5493A81D2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5493A81A2A471E36001EBA08 /* JustOneThingProvider.swift */; }; + 54EB3C1F2A5434A30082B059 /* Thing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54EB3C1E2A5434A30082B059 /* Thing.swift */; }; + 54EB3C202A5434A30082B059 /* Thing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54EB3C1E2A5434A30082B059 /* Thing.swift */; }; + 54EB3C212A5434A30082B059 /* Thing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54EB3C1E2A5434A30082B059 /* Thing.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -128,6 +131,7 @@ 54928C462A35F8CB00095445 /* WatchWidgetExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = WatchWidgetExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 54928C4A2A35F8CB00095445 /* JustOneThingWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JustOneThingWidget.swift; sourceTree = ""; }; 5493A81A2A471E36001EBA08 /* JustOneThingProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JustOneThingProvider.swift; sourceTree = ""; }; + 54EB3C1E2A5434A30082B059 /* Thing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Thing.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -196,6 +200,7 @@ 5472018B2A3655E4005B2FCC /* WidgetShared */ = { isa = PBXGroup; children = ( + 54EB3C1E2A5434A30082B059 /* Thing.swift */, 54928C4A2A35F8CB00095445 /* JustOneThingWidget.swift */, 5493A81A2A471E36001EBA08 /* JustOneThingProvider.swift */, 54928C372A35F8B800095445 /* WidgetAssets.xcassets */, @@ -485,6 +490,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 54EB3C1F2A5434A30082B059 /* Thing.swift in Sources */, 54928C212A35F89A00095445 /* Widget.intentdefinition in Sources */, 5493A81B2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */, 547201972A461DBE005B2FCC /* JustOneThingWidget.swift in Sources */, @@ -495,6 +501,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 54EB3C202A5434A30082B059 /* Thing.swift in Sources */, 547201962A461DBE005B2FCC /* JustOneThingWidget.swift in Sources */, 5493A81C2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */, 5472018E2A36563B005B2FCC /* Widget.intentdefinition in Sources */, @@ -505,6 +512,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 54EB3C212A5434A30082B059 /* Thing.swift in Sources */, 547201902A36563C005B2FCC /* Widget.intentdefinition in Sources */, 5493A81D2A471E37001EBA08 /* JustOneThingProvider.swift in Sources */, 54928C4B2A35F8CB00095445 /* JustOneThingWidget.swift in Sources */, diff --git a/WidgetShared/JustOneThingProvider.swift b/WidgetShared/JustOneThingProvider.swift index 4f983d5..b1fdd4f 100644 --- a/WidgetShared/JustOneThingProvider.swift +++ b/WidgetShared/JustOneThingProvider.swift @@ -9,24 +9,25 @@ import WidgetKit import SwiftUI import Intents -struct Provider: IntentTimelineProvider { - func placeholder(in context: Context) -> SimpleEntry { - SimpleEntry(date: Date(), configuration: ConfigurationIntent()) +struct ThingProvider: IntentTimelineProvider { + func placeholder(in context: Context) -> ThingEntry { + ThingEntry(date: Date(), configuration: ConfigurationIntent(), thing: .placeholder) } - func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) { - let entry = SimpleEntry(date: Date(), configuration: configuration) + func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (ThingEntry) -> ()) { + let entry = ThingEntry(date: Date(), configuration: configuration, thing: .placeholder) + context. completion(entry) } - func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline) -> ()) { - var entries: [SimpleEntry] = [] + func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline) -> ()) { + var entries: [ThingEntry] = [] // Generate a timeline consisting of five entries an hour apart, starting from the current date. let currentDate = Date() for hourOffset in 0 ..< 5 { let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)! - let entry = SimpleEntry(date: entryDate, configuration: configuration) + let entry = ThingEntry(date: entryDate, configuration: configuration, thing: .placeholder) entries.append(entry) } @@ -41,7 +42,8 @@ struct Provider: IntentTimelineProvider { } } -struct SimpleEntry: TimelineEntry { +struct ThingEntry: TimelineEntry { let date: Date let configuration: ConfigurationIntent + let thing: Thing } diff --git a/WidgetShared/JustOneThingWidget.swift b/WidgetShared/JustOneThingWidget.swift index f12f807..23412ed 100644 --- a/WidgetShared/JustOneThingWidget.swift +++ b/WidgetShared/JustOneThingWidget.swift @@ -17,8 +17,8 @@ struct JustOneThingWidgetBundle: WidgetBundle { } -struct JustOneThingWidgetEntryView : View { - var entry: Provider.Entry +struct ThingEntryView : View { + var entry: ThingProvider.Entry var body: some View { Text(entry.date, style: .time) @@ -29,8 +29,10 @@ struct JustOneThingWidget: Widget { let kind: String = "JustOneThingWidget" var body: some WidgetConfiguration { - IntentConfiguration(kind: kind, intent: ConfigurationIntent.self, provider: Provider()) { entry in - JustOneThingWidgetEntryView(entry: entry) + IntentConfiguration(kind: kind, + intent: ConfigurationIntent.self, + provider: ThingProvider()) { entry in + ThingEntryView(entry: entry) } .configurationDisplayName("My Widget") .description("This is an example widget.") @@ -39,7 +41,7 @@ struct JustOneThingWidget: Widget { struct Widget_Previews: PreviewProvider { static var previews: some View { - JustOneThingWidgetEntryView(entry: SimpleEntry(date: Date(), configuration: ConfigurationIntent())) + ThingEntryView(entry: ThingEntry(date: Date(), configuration: ConfigurationIntent(), thing: .placeholder)) #if os(watchOS) .previewContext(WidgetPreviewContext(family: .accessoryRectangular)) #else diff --git a/WidgetShared/Thing.swift b/WidgetShared/Thing.swift new file mode 100644 index 0000000..8faf765 --- /dev/null +++ b/WidgetShared/Thing.swift @@ -0,0 +1,15 @@ +// +// Thing.swift +// JustOneThing +// +// Created by Alan Francis on 04/07/2023. +// + +import Foundation + +struct Thing { + let text: String + let createdAt: Date + + static let placeholder: Thing = Thing(text: "placeholder", createdAt: Date.now) +}