UserDefaultsStore alternatives and similar libraries
Based on the "Database" category.
Alternatively, view UserDefaultsStore alternatives based on common mentions on social networks and blogs.
-
MMKV
An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, POSIX, and OHOS. -
YapDatabase
YapDB is a collection/key/value store with a plugin architecture. It's built atop sqlite, for Swift & objective-c developers. -
ParseAlternatives
DISCONTINUED. GraphQLite is a toolkit to work with GraphQL servers easily. It also provides several other features to make life easier during iOS application development. [Moved to: https://github.com/relatedcode/GraphQLite] -
Unrealm
Unrealm is an extension on RealmCocoa, which enables Swift native types to be saved in Realm. -
Prephirences
Prephirences is a Swift library that provides useful protocols and convenience methods to manage application preferences, configurations and app-state. UserDefaults -
PredicateEditor
A GUI for dynamically creating NSPredicates at runtime to query data in your iOS app. -
realm-cocoa-converter
A library that provides the ability to import/export Realm files from a variety of data container formats. -
SecureDefaults
Elevate the security of your UserDefaults with this lightweight wrapper that adds a layer of AES-256 encryption -
MySQL
A stand-alone Swift wrapper around the MySQL client library, enabling access to MySQL servers. -
PersistenceKit
Store and retrieve Codable objects to various persistence layers, in a couple lines of code! -
PersistentStorageSerializable
Swift library that makes easier to serialize the user's preferences (app's settings) with system User Defaults or Property List file on disk. -
PostgreSQL
A stand-alone Swift wrapper around the libpq client library, enabling access to PostgreSQL servers. -
MongoDB
A stand-alone Swift wrapper around the mongo-c client library, enabling access to MongoDB servers. -
ObjectiveRocks
An Objective-C wrapper for RocksDB - A Persistent Key-Value Store for Flash and RAM Storage. -
FileMaker
A stand-alone Swift wrapper around the FileMaker XML Web publishing interface, enabling access to FileMaker servers.
CodeRabbit: AI Code Reviews for Developers

* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of UserDefaultsStore or a related project?
README
tl;dr
You love Swift's Codable
protocol and use it everywhere, who doesn't! Here is an easy and very light way to store and retrieve -reasonable amount ๐
- of Codable
objects, in a couple lines of code!
Introducing v2.0
- Removed the
Identifiable
protocol in favor of Swift'sIdentifiable
. - Increased deployment targets to iOS
13.0
,tvOS 13.0
,macOS 10.15
, andwatchOS 6.0
. - Objects defined as non-final classes can now be used as well.
- Added new
generateSnapshot()
andrestoreSnapshot(_:)
methods to generate and restore aSnapshot
object that can be saved (e.g. to iCloud) and restored later. - Fixed a bug where
objectsCount
might run out of sync with the actual count of objects in store.
Installation
Swift Package Manager (Recommended) You can use The Swift Package Manager to install UserDefaultsStore by adding the proper description to your Package.swift file:
import PackageDescription
let package = Package( name: "YOUR_PROJECT_NAME", targets: [], dependencies: [ .package(url: "https://github.com/omaralbeik/UserDefaultsStore.git", from: "2.0.0") ] )
Next, add UserDefaultsStore to your targets dependencies like so: .target( name: "YOUR_TARGET_NAME", dependencies: [ "UserDefaultsStore", ] ), Then run swift package update.
CocoaPods To integrate UserDefaultsStore into your Xcode project using CocoaPods, specify it in your Podfile: pod 'UserDefaultsStore'
Carthage To integrate UserDefaultsStore into your Xcode project using Carthage, specify it in your Cartfile:
github "omaralbeik/UserDefaultsStore" ~> 2.0.0
Manually Add the Sources folder to your Xcode project.
Usage
Let's say you have 2 structs; User
and Laptop
defined as bellow:
struct User: Codable {
var id: Int
var firstName: String
var lastName: String
var laptop: Laptop?
}
struct Laptop: Codable {
var model: String
var name: String
}
Here is how you store them in UserDefaultsStore:
1. Conform to the Identifiable
protocol and set the id
property
The Identifiable
protocol lets UserDefaultsStore knows what is the unique id for each object.
struct User: Codable, Identifiable {
...
}
struct Laptop: Codable, Identifiable {
var id: String { model }
...
}
2. Create UserDefaults Stores
let usersStore = UserDefaultsStore<User>(uniqueIdentifier: "users")
let laptopsStore = UserDefaultsStore<Laptop>(uniqueIdentifier: "laptops")
3. Voilร , you're all set!
let macbook = Laptop(model: "A1278", name: "MacBook Pro")
let john = User(id: 1, firstName: "John", lastName: "Appleseed", laptop: macbook)
// Save an object to a store
try! usersStore.save(john)
// Save an array of objects to a store
try! usersStore.save([jane, steve, jessica])
// Get an object from store
let user = store.object(withId: 1)
let laptop = store.object(withId: "A1278")
// Get all objects in a store
let laptops = laptopsStore.allObjects()
// Check if store has an object
print(usersStore.hasObject(withId: 10)) // false
// Iterate over all objects in a store
laptopsStore.forEach { laptop in
print(laptop.name)
}
// Delete an object from a store
usersStore.delete(withId: 1)
// Delete all objects in a store
laptops.deleteAll()
// Know how many objects are stored in a store
let usersCount = usersStore.objectsCount
// Create a snapshot
let snapshot = usersStore.generateSnapshot()
// Restore a pre-generated snapshot
try? usersStore.restoreSnapshot(snapshot)
Looking to store a single item only?
Use SingleUserDefaultsStore
, it enables storing and retrieving a single value of Int
, Double
, String
, or any Codable
type.
Requirements
- iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+
- Swift 5.0+
Thanks
Special thanks to:
- Paul Hudson for his article on how to use Swift keypaths to write more natural code.
- Batuhan Saka for translating this document into Turkish.
Credits
Icon made by freepik from flaticon.com.
License
UserDefaultsStore is released under the MIT license. See LICENSE for more information.
*Note that all licence references and agreements mentioned in the UserDefaultsStore README section above
are relevant to that project's source code only.