explaingit

sindresorhus/defaults

Analysis updated 2026-05-18

2,465SwiftAudience · developerComplexity · 2/5Setup · easy

TLDR

A Swift library that adds type safety, SwiftUI support, and iCloud sync on top of Apple's UserDefaults for storing app settings.

Mindmap

mindmap
  root((Defaults))
    What it does
      Type safe settings
      SwiftUI property wrapper
      iCloud sync
    Tech stack
      Swift
      UserDefaults
      SwiftUI
    Use cases
      App preferences
      SwiftUI bound settings
      Custom Codable types
    Audience
      iOS developers
      macOS developers

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Store and retrieve typed app settings without manually tracking string keys and types.

USE CASE 2

Bind a SwiftUI view directly to a stored setting so the UI updates automatically when it changes.

USE CASE 3

Sync user preferences across a person's devices using iCloud.

USE CASE 4

Store custom Codable types like enums as persisted settings.

What is it built with?

SwiftUserDefaultsSwiftUISwift Package Manager

How does it compare?

sindresorhus/defaultssindresorhus/keyboardshortcutsvorssaint/vorssaint-utils
Stars2,4652,6302,265
LanguageSwiftSwiftSwift
Last pushed2026-07-03
MaintenanceActive
Setup difficultyeasyeasyeasy
Complexity2/52/52/5
Audiencedeveloperdevelopergeneral

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

In plain English

Defaults is a Swift library that makes it easier for Apple platform developers to store and retrieve simple settings in their apps. It wraps the built-in UserDefaults system, which is the standard way to save small pieces of data (like user preferences) that persist across app launches on iOS, macOS, watchOS, tvOS, and visionOS. The main improvement over using UserDefaults directly is type safety. With plain UserDefaults you store and retrieve values using string keys and you have to remember the correct type yourself, which can lead to mistakes. With this library you declare each setting once with a name and a default value and a specific type, and the compiler enforces that you always use it correctly from then on. For developers building apps with SwiftUI, Apple's modern UI framework, the library provides a property wrapper that automatically updates the interface whenever a saved value changes, similar to how SwiftUI's own built-in storage property wrapper works. The library documents several advantages over that built-in alternative: definitions are centralized, the default value only needs to be stated once, it works outside of SwiftUI views, and it supports a wider variety of data types including any type that conforms to Swift's Codable standard. The library also supports observing changes to specific keys, synchronizing data to iCloud so settings follow the user across their devices, and storing custom types by providing your own serialization logic. Stored values are saved as JSON, which makes them easy to inspect when debugging. It is available as a Swift Package and is used in production across the author's own apps.

Copy-paste prompts

Prompt 1
Show me how to add the Defaults Swift package to my Xcode project and define a typed setting.
Prompt 2
Help me bind a SwiftUI Slider to a Defaults key so it updates automatically.
Prompt 3
Explain how to sync a Defaults setting to iCloud across a user's devices.
Prompt 4
How do I observe changes to a specific Defaults key in my Swift app?

Frequently asked questions

What is defaults?

A Swift library that adds type safety, SwiftUI support, and iCloud sync on top of Apple's UserDefaults for storing app settings.

What language is defaults written in?

Mainly Swift. The stack also includes Swift, UserDefaults, SwiftUI.

How hard is defaults to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is defaults for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.