
A simple but surprisingly fancy data store and so much more
"I ripped out Core Data, this is the way it should work"
— Josh Holtz
"Boutique is ridiculously easy to implement and makes persistence a breeze. It's become my first addition to every project I start.
— Tyler Hillsman
"Boutique has become invaluable, I use it in every side project now. Not having to care about persistence is great and the cost of getting started is practically zero."
— Romain Pouclet
If you find Boutique valuable I would really appreciate it if you would consider helping sponsor my open source work, so I can continue to work on projects like Boutique to help developers like yourself.
Table of Contents
Intro
Boutique is a simple but powerful persistence library, a small set of property wrappers and types that enable building incredibly simple state-driven apps for SwiftUI, UIKit, and AppKit. With its dual-layered memory + disk caching architecture, Boutique provides a way to build apps that update in real time with full offline storage in only a few lines of code — using an incredibly simple API.
- Boutique is used in hundreds of apps, and I thoroughly test every API in my app Plinky. (Which I highly recommend downloading and maybe even subscribing to. 😉)
- Boutique is built atop Bodega, and you can find a demo app built atop the Model View Controller Store architecture in this repo which shows you how to make an offline-ready SwiftUI app in only a few lines of code. You can read more about the thinking behind the architecture in this blog post exploring the MVCS architecture.
Getting Started
Boutique only has one concept you need to understand. When you save data to the Store your data will be persisted automatically for you and exposed as a regular Swift array. The @StoredValue and @SecurelyStoredValue property wrappers work the same way, but instead of an array they work with singular Swift values. You'll never have to think about databases, everything in your app is a regular Swift array or value using your app's models, with straightforward code that looks like any other app.
You may be familiar with the Store from Redux or The Composable Architecture, but unlike those frameworks you won't need to worry about adding Actions or Reducers. With this Store implementation all your data is persisted for you automatically, no additional code required. This allows you to build realtime updating apps with full offline support in an incredibly simple and straightforward manner.
You can read a high level overview of Boutique below, but Boutique is also fully documented here.
Store
We'll go through a high level overview of the Store below, but the Store is fully documented with context, use cases, and examples here.
The entire surface area of the API for achieving full offline support and realtime model updates across your entire app is three methods, .insert(), .remove(), and .removeAll().
// Create a Store ¹
let store = Store<Animal>(
storage: SQLiteStorageEngine.default(appendingPath: "Animals"),
cacheIdentifier: \.id
)
// Insert an item into the Store ²
let redPanda = Animal(id: "red_panda")
try await store.insert(redPanda)
// Remove an animal from the Store
try await store.remove(redPanda)
// Insert two more animals to the Store
let dog = Animal(id: "dog")
let cat = Animal(id: "cat")
try await store.insert([dog, cat])
// You can read items directly
print(store.items) // Prints [dog, cat]
// You also don't have to worry about maintaining uniqueness, the Store handles uniqueness for you
let secondDog = Animal(id: "dog")
try await store.insert(secondDog)
print(store.items) // Prints [dog, cat]
// Clear your store by removing all the items at once.
store.removeAll()
print(store.items) // Prints []
// You can even chain commands together
try await store
.insert(dog)
.insert(cat)
.run()