DataStoreManager is a persistent data framework written in Swift and can be used with Objective-C.
import DataStoreManager
class ViewController: UIViewController {
let manager = DataStoreManager(identifier: "Example")
func fetchFromDataStore() {
manager.read(forKey: "Age", withObjectType: Int.self, forType: .userDefaults) { (object, _, _) in
if let object = object {
print("successfully read int \(object) from UserDefaults")
}
}
manager.read(forKey: "Balance", withObjectType: Decimal.self, forType: .genericKeychain) { (object, _, _) in
if let object = object {
print("successfully read decimal \(object) from Generic Keychain")
}
}
manager.read(forKey: "temp_file.txt", withObjectType: String.self, forType: .temporaryDirectory) { (object, _, _) in
if let object = object {
print("successfully read string \(object) from /tmp")
}
}
manager.read(forKey: "Image", withObjectType: UIImage.self, forType: .cache) { (object, _, _) in
if let object = object {
print("successfully read image \(object) from NSCache")
}
}
}
func storeToDataStore(object aObject: Any) {
manager.create(object: aObject, forKey: "Text", forType: .userDefaults) { (isSuccessful, _, _) in
if isSuccessful {
print("successfully create object at UserDefaults")
}
}
manager.update(object: aObject, forKey: "Text", forType: .genericKeychain) { (isSuccessful, _, _) in
if isSuccessful {
print("successfully update object at Generic Keychain")
}
}
manager.create(object: aObject, forKey: "Inbox/file.txt", forType: .documentDirectory) { (isSuccessful, _, _) in
if isSuccessful {
print("successfully create file at Inbox Document Directory")
}
}
let exampleModel = DynamicModel(name: "Text", number: 123)
manager.create(object: exampleModel, forKey: "column_name", forType: .privateCloudDatabase) { (isSuccessful, recordID, _) in
if isSuccessful {
print("successfully create model at CloudKit Private Database with ID \(recordID)")
}
}
}
}
Available storage types:
/// UserDefaults
.userDefaults
/// FileManager (~/Documents)
.documentDirectory
/// FileManager (/Users)
.userDirectory
/// FileManager (/Library)
.libraryDirectory
/// FileManager (/Applications)
.applicationDirectory
/// FileManager (/System/Library/CoreServices)
.coreServiceDirectory
/// FileManager (/tmp)
.temporaryDirectory
/// NSCache
.cache
/// Keychain (kSecClassGenericPassword)
.genericKeychain
/// Keychain (kSecClassInternetPassword)
.internetKeychain
/// CoreData
.coreData
/// CloudKit (.privateCloudDatabase)
.privateCloudDatabase
/// CloudKit (.publicCloudDatabase)
.publicCloudDatabase
/// CloudKit (.sharedCloudDatabase)
.sharedCloudDatabase
/// NSUbiquitousKeyValueStore
.ubiquitousCloudStore
- iOS 8.0+
- macOS 10.10+
- watchOS 2.0+
- tvOS 9.0+
- Xcode 10.2+
To install it, simply add the following line to your Cartfile:
github "zaidmsaid/DataStoreManager"
Then run carthage update
.
Follow the current instructions in Carthage's README for up to date installation instructions.
To install it, simply add the following line to your Podfile:
pod "DataStoreManager"
You will also need to make sure you're opting into using frameworks:
use_frameworks!
Then run pod install
with CocoaPods 1.6.0 or newer.
To install it, simply add the following line to your Package.swift:
dependencies: [
.package(url: "https://github.com/zaidmsaid/DataStoreManager.git", .upToNextMinor(from: "0.9.3"))
]
or more strict:
dependencies: [
.package(url: "https://github.com/zaidmsaid/DataStoreManager.git", .exact("0.9.3"))
]
Then run swift package update
.
To install DataStoreManager to your project, simply follow the following steps:
- Add DataStoreManager as a submodule by opening the Terminal,
cd
-ing into your top-level project directory, and entering the commandgit submodule add https://github.com/zaidmsaid/DataStoreManager.git
- Open the
DataStoreManager
folder, and dragDataStoreManager.xcodeproj
into the file navigator of your app project. - In Xcode, navigate to the target configuration window by clicking on the blue project icon, and selecting the application target under the "Targets" heading in the sidebar.
- Ensure that the deployment target of
DataStoreManager.framework
matches that of the application target. - In the tab bar at the top of that window, open the "Build Phases" panel.
- Expand the "Link Binary with Libraries" group, and add
DataStoreManager.framework
. - Click on the
+
button at the top left of the panel and select "New Copy Files Phase". Rename this new phase to "Copy Frameworks", set the "Destination" to "Frameworks", and addDataStoreManager.framework
.
Having trouble with DataStoreManager? Check out our documentation.
Please read CONTRIBUTING.md and CODE_OF_CONDUCT.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Zaid M. Said - Initial work - @SentulAsia
See also the list of contributors who participated in this project.
This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details
- Hat tip to anyone whose code was used