{"id":2250,"date":"2021-01-31T17:09:50","date_gmt":"2021-01-31T22:09:50","guid":{"rendered":"http:\/\/michaelrowe01.com\/?p=2250"},"modified":"2022-12-15T06:46:04","modified_gmt":"2022-12-15T11:46:04","slug":"wastedtime-watch-progress","status":"publish","type":"post","link":"https:\/\/michaelrowe01.com\/index.php\/uncategorized\/wastedtime-watch-progress\/","title":{"rendered":"WastedTime Watch &#8211; Progress"},"content":{"rendered":"\n<p>Ok, I had basically gotten frustrated trying to change WastedTime Watch to a fully SwiftUI based app.  Apple changed the App Entry point which had completely changed how the AppDelegate function worked.  I thought this app was the simplest of my apps, so I could easily convert it to the new Swift Architecture.  Boy was I mistaken.<\/p>\n\n\n\n<p>In September, after banging my head against the wall for days, I posted the problem on StackOverflow, and walked away.  Over the last few months, I got a coupled of suggestions, but severally figured out how to address the problems. <\/p>\n\n\n\n<p>The net of the problem was I could not create my start up objects multiple times, but always ended up with a nil object.  The basic startup of the application had changed, and I was not following it.  <\/p>\n\n\n\n<p>Today while trying another suggestion, I finally realized that the problem was (here comes the big surprising reveal) &#8211; Me!  I had been using a local object instead of the delegate I created.  here&#8217;s the basic structure of the now working code!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\n\/\/  WastedTimeWatchApp.swift\n\/\/  TestMe WatchKit Extension\n\/\/\n\/\/  Created by Michael Rowe on 9\/22\/20.\n\/\/  Copyright \u00a9 2020 Michael Rowe. All rights reserved.\n\/\/\n\nimport SwiftUI\n\nstruct DelegateKey: EnvironmentKey {\n    typealias Value = ExtensionDelegate\n    static let defaultValue: ExtensionDelegate = ExtensionDelegate()\n}\n\nextension EnvironmentValues {\n    var extensionDelegate: DelegateKey.Value {\n        get {\n            return self&#91;DelegateKey.self]\n        }\n        set {\n            self&#91;DelegateKey.self] = newValue\n        }\n    }\n}\n\n@main\nstruct WastedTimeWatchApp: App {\n    \n    @WKExtensionDelegateAdaptor(ExtensionDelegate.self) var delegate\n    \n    let prefs:UserDefaults = UserDefaults(suiteName: suiteName)!\n    \n    @SceneBuilder var body: some Scene {\n        WindowGroup {\n            NavigationView {\n                ContentView()\n                    .environment(\\.extensionDelegate, delegate)\n            }\n        }\n        WKNotificationScene(controller: NotificationController.self, category: \"myCategory\")\n    }\n}\n\nclass ExtensionDelegate: NSObject, WKExtensionDelegate, ObservableObject {\n    \n    @Environment(\\.extensionDelegate) static var shared\n\n    var meetingSetup: MeetingSetup!\n    var meetingStatistics:  MeetingStatistics!\n    var meeting: Meeting!\n    \n    func applicationDidFinishLaunching() {\n        \/\/ Perform any final initialization of your application.\n        print(\"applicationDidFinishLaunching for watchOS\")\n        ExtensionDelegate.shared.meetingSetup = MeetingSetup()\n        ExtensionDelegate.shared.meetingStatistics = MeetingStatistics()\n        ExtensionDelegate.shared.meeting = Meeting()\n    }\n}\n<\/code><\/pre>\n\n\n\n<p> The secrete ended up being that I had been using self.meeting = Meeting() in applicationDidFinishLaunch which was never actually exposed to the rest of the program.  Now I should able to clean up a few simple problems in the views, and release version 2.0 of Wasted Time for the Watch<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ok, I had basically gotten frustrated trying to change WastedTime Watch to a fully SwiftUI based app. Apple changed the App Entry point which had completely changed how the AppDelegate function worked. I thought this app was the simplest of my apps, so I could easily convert it to the new Swift Architecture. Boy was [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_wp_convertkit_post_meta":{"form":"-1","landing_page":"0","tag":"0","restrict_content":"0"},"hide_page_title":"","footnotes":""},"categories":[1],"tags":[379,527,538],"class_list":["post-2250","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-swift","tag-swiftui","tag-wastedtime-watch"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/2250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/comments?post=2250"}],"version-history":[{"count":2,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/2250\/revisions"}],"predecessor-version":[{"id":2252,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/2250\/revisions\/2252"}],"wp:attachment":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/media?parent=2250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/categories?post=2250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/tags?post=2250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}