PersistentStorageSerializable alternatives and similar libraries
Based on the "Database" category.
Alternatively, view PersistentStorageSerializable alternatives based on common mentions on social networks and blogs.
-
Realm
Realm is a mobile database: a replacement for Core Data & SQLite -
MMKV
An efficient, small mobile key-value storage framework developed by WeChat. Works on Android, iOS, macOS, Windows, and POSIX. -
SQLite.swift
A type-safe, Swift-language layer over SQLite3. -
WCDB
WCDB is a cross-platform database framework developed by WeChat. -
GRDB.swift
A toolkit for SQLite databases, with a focus on application development -
SwiftyUserDefaults
Modern Swift API for NSUserDefaults -
YapDatabase
YapDB is a collection/key/value store with a plugin architecture. It's built atop sqlite, for Swift & objective-c developers. -
ParseAlternatives
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] -
SugarRecord
CoreData/Realm sweet wrapper written in Swift -
Couchbase Mobile
Lightweight, embedded, syncable NoSQL database engine for iOS and MacOS apps. -
FCModel
An alternative to Core Data for people who like having direct SQL access. -
UserDefaults
Simple, Strongly Typed UserDefaults for iOS, macOS and tvOS -
CTPersistance
iOS Database Persistence Layer with SQLite, your next Persistence Layer! -
Zephyr
Effortlessly synchronize UserDefaults over iCloud. -
SwiftData
Simple and Effective SQLite Handling in Swift -
MongoKitten
Native MongoDB driver for Swift, written in Swift -
Unrealm
Unrealm is an extension on RealmCocoa, which enables Swift native types to be saved in Realm. -
Shallows
๐ถ Your lightweight persistence toolbox -
Prephirences
Prephirences is a Swift library that provides useful protocols and convenience methods to manage application preferences, configurations and app-state. UserDefaults -
Default
Modern interface to UserDefaults + Codable support -
RealmIncrementalStore
Realm-powered Core Data persistent store -
ObjectBox
Swift database - fast, simple and lightweight (iOS, macOS) -
UserDefaultsStore
Why not use UserDefaults to store Codable objects ๐ -
PredicateEditor
A GUI for dynamically creating NSPredicates at runtime to query data in your iOS app. -
Nora
Nora is a Firebase abstraction layer for FirebaseDatabase and FirebaseStorage -
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 an additional layer of AES-256 encryption -
MySQL
A stand-alone Swift wrapper around the MySQL client library, enabling access to MySQL servers. -
RealmGeoQueries
Realm GeoQueries made easy -
PersistenceKit
Store and retrieve Codable objects to various persistence layers, in a couple lines of code! -
SwiftStore
Key-Value store for Swift backed by LevelDB -
YapDatabaseExtensions
YapDatabase extensions for use with Swift -
TypedDefaults
TypedDefaults is a utility library to type-safely use NSUserDefaults. -
RealmWrapper
Safe and easy wrappers for RealmSwift -
MongoDB
A stand-alone Swift wrapper around the mongo-c client library, enabling access to MongoDB servers. -
PostgreSQL
A stand-alone Swift wrapper around the libpq client library, enabling access to PostgreSQL servers. -
ObjectiveRocks
An Objective-C wrapper for RocksDB - A Persistent Key-Value Store for Flash and RAM Storage. -
SQLite
A stand-alone Swift wrapper around the SQLite 3 client library. -
Storez
๐พ Safe, statically-typed, store-agnostic key-value storage written in Swift! -
FileMaker
A stand-alone Swift wrapper around the FileMaker XML Web publishing interface, enabling access to FileMaker servers.
Appwrite - The Open Source Firebase alternative introduces iOS support
* 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 PersistentStorageSerializable or a related project?
README
PersistentStorageSerializable
PersistentStorageSerializable
is a protocol for automatic serialization and deserialization of Swift class, struct or NSObject descendant object into and from User Defaults or Property List file.
The adopting type properties must be of property list type (String, Data, Date, Int, UInt, Float, Double, Bool, Array or Dictionary of above). If you want to store any other type of object, you should typically archive it to create an instance of Data. The URL properties can be stored in User Defaults storage but not in Plist storage. In the last case, you have to archive it to/from Data.
The PersistentStorageSerializable
protocol provides default implementations of init(from:)
initializer and persist()
function. The library defines two classes of PesistentStorage
protocol: UserDefaultsStorage
and PlistStorage
. Object of one of those types is passed as the argument when calling to init(from:)
initializer to specify which storage to be used for serialization/deserialization.
Functions of the PersistentStorageSerializable
protocol traverses the adopting type object and gets/sets it's properties values via Reflection library. The NSObject class descendant properties values are get/set via KVC.
How to use
Serialize/Deserialize a struct with User Defaults by using UserDefaultStorage
as shown below:
struct Settings: PersistentStorageSerializable {
var flag = false
var title = ""
var number = 1
var dictionary: [String : Any] = ["Number" : 1, "Distance" : 25.4, "Label" : "Hello"]
// MARK: Adopt PersistentStorageSerializable
var persistentStorage: PersistentStorage!
var persistentStorageKeyPrefix: String! = "Settings"
}
// Init from User Defaults
var mySettings = try! Settings(from: UserDefaultsStorage.standard)
mySettings.flag = true
// Persist into User Defaults
try! mySettings.persist()
To serialize data with Plist file use PlistStorage
class:
// Init from plist
let plistUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!.appendingPathComponent("storage.plist")
var settingsOnDisk = try! Settings(from: PlistStorage(at: plistUrl))
mySettings.flag = true
// Persist on disk
try! mySettings.persist()
Reading data stored by the previous version of the app
When you have some data persisted in User Defaults by the previous version of the app and want to read that data into a structure you need to provide a mapping between properties names and User Defaults keys by overloading the persistentStorageKey(for:)
function.
Say we have following data persisted in User Defaults:
UserDefaults.standard.set("Superhero", forKey: "oldGoogTitle")
UserDefaults.standard.set(true, forKey: "well.persisted.option")
We want those to be serialized with the object of ApplicationConfiguration
class.
final class ApplicationConfiguration: PersistentStorageSerializable {
var title = ""
var showIntro = false
// MARK: Adopt PersistentStorageSerializable
var persistentStorage: PersistentStorage!
var persistentStorageKeyPrefix: String!
}
// Provide key mapping by overloading `persistentStorageKey(for:)` function.
extension ApplicationConfiguration {
func persistentStorageKey(for propertyName: String) -> String {
let keyMap = ["title" : "oldGoogTitle", "showIntro" : "well.persisted.option"]
return keyMap[propertyName]!
}
}
// Now we can load data persisted in the storage.
let configuration = try! ApplicationConfiguration(from: UserDefaultsStorage.standard)
print(configuration.title) // prints Superhero
print(configuration.showIntro) // prints true
Example
To run example projects for iOS/macOS, run pod try PersistentStorageSerializable
in the terminal.
Requirements
- Xcode 8.3
- Swift 3.1
Installation
CocoaPods
PersistentStorageSerializable is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "PersistentStorageSerializable"
and run pods update
or pods install
.
:sparkles: For Xcode 9, Swift 4 and cocoapods installation, please follow the instruction here.
Carthage
If you use Carthage to manage your dependencies, simply add PersistentStorageSerializable to your Cartfile:
github "IvanRublev/PersistentStorageSerializable"
If you use Carthage to build your dependencies, make sure you have added PersistentStorageSerializable.framework
and Reflection.framework
to the "Linked Frameworks and Libraries" section of your target, and have included them in your Carthage framework copying build phase.
Author
Copyright (c) 2017, IvanRublev, [email protected]
License
PersistentStorageSerializable is available under the MIT license. See the LICENSE file for more info.
*Note that all licence references and agreements mentioned in the PersistentStorageSerializable README section above
are relevant to that project's source code only.