All Projects → Teknasyon-Teknoloji → Persistencekit

Teknasyon-Teknoloji / Persistencekit

Licence: mit
Store and retrieve Codable objects to various persistence layers, in a couple lines of code!

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Persistencekit

swift-standard-clients
Client declarations and live implementations for standard iOS managers
Stars: ✭ 28 (-76.86%)
Mutual labels:  tvos, watchos, keychain, userdefaults
Valet
Valet lets you securely store data in the iOS, tvOS, or macOS Keychain without knowing a thing about how the Keychain works. It’s easy. We promise.
Stars: ✭ 3,712 (+2967.77%)
Mutual labels:  tvos, watchos, keychain
Userdefaultsstore
Why not use UserDefaults to store Codable objects 😉
Stars: ✭ 416 (+243.8%)
Mutual labels:  userdefaults, tvos, watchos
Diff
Simple diff library in pure Swift
Stars: ✭ 110 (-9.09%)
Mutual labels:  tvos, watchos
Swiftui Kit
A SwiftUI system components and interactions demo app
Stars: ✭ 1,733 (+1332.23%)
Mutual labels:  tvos, watchos
Prex
🔁Unidirectional data flow architecture with MVP and Flux combination for Swift
Stars: ✭ 102 (-15.7%)
Mutual labels:  tvos, watchos
Mixpanel
Unofficial Swift Mixpanel client
Stars: ✭ 93 (-23.14%)
Mutual labels:  tvos, watchos
Swift Sdk
LeanCloud Swift SDK
Stars: ✭ 110 (-9.09%)
Mutual labels:  tvos, watchos
Awesome Rubymotion
A collection of awesome RubyMotion example apps, libraries, tools, frameworks, software and resources
Stars: ✭ 103 (-14.88%)
Mutual labels:  tvos, watchos
Mapbox Directions Swift
Traffic-aware directions and map matching in Swift on iOS, macOS, tvOS, watchOS, and Linux
Stars: ✭ 115 (-4.96%)
Mutual labels:  tvos, watchos
Conbini
Publishers, operators, and subscribers to supplement Combine.
Stars: ✭ 109 (-9.92%)
Mutual labels:  tvos, watchos
Predicateflow
Write amazing, strong-typed and easy-to-read NSPredicate.
Stars: ✭ 98 (-19.01%)
Mutual labels:  tvos, watchos
Defaultskit
Simple, Strongly Typed UserDefaults for iOS, macOS and tvOS
Stars: ✭ 1,343 (+1009.92%)
Mutual labels:  userdefaults, tvos
Sdwebimagewebpcoder
A WebP coder plugin for SDWebImage, use libwebp
Stars: ✭ 101 (-16.53%)
Mutual labels:  tvos, watchos
Egocache
Fast Caching for Objective-C (iPhone & Mac Compatible)
Stars: ✭ 1,339 (+1006.61%)
Mutual labels:  tvos, watchos
Mapboxgeocoder.swift
Address search and reverse geocoding in Swift or Objective-C on iOS, macOS, tvOS, and watchOS
Stars: ✭ 115 (-4.96%)
Mutual labels:  tvos, watchos
Sniffer
Networking activity logger for Swift
Stars: ✭ 108 (-10.74%)
Mutual labels:  tvos, watchos
Surmagic
🚀 The better way to deal with Binary Frameworks on iOS, Mac Catalyst, tvOS, macOS, and watchOS. Create XCFrameworks with ease.
Stars: ✭ 119 (-1.65%)
Mutual labels:  tvos, watchos
Articles Zh Hans
Articles for NSHipster.cn
Stars: ✭ 113 (-6.61%)
Mutual labels:  tvos, watchos
Extendable
Blocks Based Bluetooth LE Connectivity framework for iOS/watchOS/tvOS/OSX. Quickly configure centrals & peripherals, perform read/write operations, and respond characteristic updates.
Stars: ✭ 88 (-27.27%)
Mutual labels:  tvos, watchos

Build Status Test Coverage Platforms Cocoapods Carthage compatible Swift Package Manager compatible Swift Xcode MIT

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 Codable objects to various persistence layers, in a few lines of code!

Persistence Layers

PersistenceKit offers 3 layers of persistence suitable for most use cases:

1. UserDefaults

  • Stores data using UserDefaults.
  • Suitable for storing a reasonable number of objects.

2. Files

  • Stores data directly to directories in the app's documents directory using FileManager.
  • Suitable for storing large number of objects.

3. Keychain

  • Stores data to OS's keychain using the Security Framework.
  • Suitable for storing sensitive data, like access tokens.

What's new in v1.3

v1.3 brings Swift 5.0 support

Installation

CocoaPods

To integrate PersistenceKit into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'PersistenceKit'
Carthage

To integrate PersistenceKit into your Xcode project using Carthage, specify it in your Cartfile:

github "Teknasyon-Teknoloji/PersistenceKit"
Swift Package Manager

You can use The Swift Package Manager to install PersistenceKit 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/Teknasyon-Teknoloji/PersistenceKit.git", from: "0.1")
  ]
)

Note that the Swift Package Manager is still in early design and development, for more information checkout its GitHub Page

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
}

1. Conform to the Identifiable protocol and set the idKey property

The Identifiable protocol lets PersistenceKit knows what is the unique id for each object.

struct User: Codable, Identifiable {
	static let idKey = \User.id
	...
}
struct Laptop: Codable, Identifiable {
	static let idKey = \Laptop.model
	...
}

Notice how User uses Int for its id, while Laptop uses String, in fact the id can be any type. PersistenceKit uses Swift keypaths to refer to properties without actually invoking them. Swift rocks 🤘

2 Create Stores

// To save objects to UserDefaults, create UserDefaultsStore:
let usersStore = UserDefaultsStore<User>(uniqueIdentifier: "users")!
let laptopsStore = UserDefaultsStore<Laptop>(uniqueIdentifier: "laptops")!

// To save a single object to UserDefaults, create UserDefaultsStore:
let userStore = SingleUserDefaultsStore<User>(uniqueIdentifier: "user")!

// To save objects to the file system, create FilesStore:
let usersStore = FilesStore<User>(uniqueIdentifier: "users")
let laptopsStore = FilesStore<Laptop>(uniqueIdentifier: "laptops")

// To save a single object to the file system, create SingleFilesStore:
let userStore = SingleFilesStore<User>(uniqueIdentifier: "user")

// To save a single object to the system's keychain, create SingleKeychainStore:
let userStore = SingleKeychainStore<User>(uniqueIdentifier: "user")

3. Voilà, you're all set!

let macbook = Laptop(model: "A1278", name: "MacBook Pro")
let john = User(userId: 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

Requirements

  • iOS 8.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 10.0+
  • Swift 4.2+

Thanks

Special thanks to:

Credits

License

PersistenceKit is released under the MIT license. See LICENSE for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].