When sharing data between targets using UserDefaults

When you have to use UserDefaults to share data between a core app and a widget you have to do a couple of things.

Inside of the project Signing & Capabilities use the Add Capabilities button to add App Group. You need to do this while selecting both the app target and the widget target.

extension UserDefaults {
    static let custom: UserDefaults = {
        let appGroupId = "group.tech.justins.BowlingScoreTracker"
        return UserDefaults(suiteName: appGroupId)!
    }()
}

Now anywhere in the app where you set or get from UserDefaults just use .custom instead of .default. And that will synchronize across both of them.