Skip to content
DataStoreManager is a persistent data framework written in Swift and can be used with Objective-C.
Branch: master
Clone or download
Latest commit e143a8a Jul 21, 2019

README.md

DataStoreManager

Swift 5 Platform Carthage compatible CocoaPods License Reviewed by Hound Documentation Twitter

DataStoreManager is a persistent data framework written in Swift and can be used with Objective-C.

Usage

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

Prerequisites

  • iOS 8.0+
  • macOS 10.10+
  • watchOS 2.0+
  • tvOS 9.0+
  • Xcode 10.2+

Installing

Carthage

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.

CocoaPods

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.

Swift Package Manager

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.

Git Submodule

To install DataStoreManager to your project, simply follow the following steps:

  1. Add DataStoreManager as a submodule by opening the Terminal, cd-ing into your top-level project directory, and entering the command git submodule add https://github.com/zaidmsaid/DataStoreManager.git
  2. Open the DataStoreManager folder, and drag DataStoreManager.xcodeproj into the file navigator of your app project.
  3. 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.
  4. Ensure that the deployment target of DataStoreManager.framework matches that of the application target.
  5. In the tab bar at the top of that window, open the "Build Phases" panel.
  6. Expand the "Link Binary with Libraries" group, and add DataStoreManager.framework.
  7. 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 add DataStoreManager.framework.

Documentation

Having trouble with DataStoreManager? Check out our documentation.

Built With

  • Xcode - The IDE used
  • jazzy - Used to generate docs

Contributing

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.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details

Acknowledgments

  • Hat tip to anyone whose code was used

analytics

You can’t perform that action at this time.