Skip to content

Instantly share code, notes, and snippets.

View AdrianTDC's full-sized avatar

Adrian Bolinger AdrianTDC

  • 19:00 (UTC -04:00)
View GitHub Profile
@AdrianTDC
AdrianTDC / UserDefault.swift
Created June 21, 2023 15:54 — forked from simonbs/UserDefault.swift
Property wrapper that stores values in UserDefaults and works with SwiftUI and Combine.
/**
* I needed a property wrapper that fulfilled the following four requirements:
*
* 1. Values are stored in UserDefaults.
* 2. Properties using the property wrapper can be used with SwiftUI.
* 3. The property wrapper exposes a Publisher to be used with Combine.
* 4. The publisher is only called when the value is updated and not
* when_any_ value stored in UserDefaults is updated.
*
* First I tried using SwiftUI's builtin @AppStorage property wrapper