Models (structures) in your project must conform to Storable.
import Arcade
struct Owner: Storable {
static var table: Table = AppTable.owner
var persistentId: String {
// Return your models unique store ID
}
var name: String?
}
Table
The Table protocol defines the names of the tables in which to store your models.
import Arcade
enum AppTable: String, Table {
case owner = "Owner"
var name: String {
return self.rawValue
}
}
Configure Adapter
import Arcade
let adapter = InMemoryAdapter()
Inserting
import Arcade
let owner = Owner(id: id(), name: "Foo")
adapter.insert(storable: owner) { (result) in
// Inserted! (or Error)
}
import Arcade
let id = owner.id
adapter.delete(id: id, type: Owner.self) { (result) in
// Deleted! (or Error)
}
Fetching
To find a specific item by id:
import Arcade
adapter.find(id: owner.id) { (result) in
// Found it! (or Error)
}
To query a set of items:
import Arcade
let expression = Expression.equal("name", "Foo")
let query = Query.expression(expression)
adapter.fetch(query: query) { (result) in
// Do something with result... (or Error)
}
CoreData
To use Arcade with the CoreData adapter some additional protocol conformance must be setup. Your
CoreData entites should conform to CoreDataStorable:
@objc(OwnerEntity)
class OwnerEntity: NSManagedObject {
@NSManaged var id: id
@NSManaged var name: String?
override func awakeFromInsert() {
super.awakeFromInsert()
self.id = id()
}
}
extension OwnerEntity: CoreDataStorable {
public var storable: Storable {
return Owner(id: self.id, name: self.name)
}
public func update(with storable: Storable) -> Bool {
if let id = storable as? id {
self.id = id
}
if let name = storable.name as? String {
self.name = name
}
return true
}
}
That’s it! Now you can save your objects using the CoreDataAdapter just like any other object!
License
Arcade is released under the MIT license. See LICENSE for details.
Arcade
Arcade is a lightweight persistence layer for Swift structures or objects!
Installation
Arcade can be installed using the Swift Package Manager. Add the following to your
Package.swift
file:Usage
Models
Models (structures) in your project must conform to
Storable
.Table
The
Table
protocol defines the names of the tables in which to store your models.Configure Adapter
Inserting
Updating
Deleting
Fetching
To find a specific item by id:
To query a set of items:
CoreData
To use Arcade with the CoreData adapter some additional protocol conformance must be setup. Your CoreData entites should conform to
CoreDataStorable
:That’s it! Now you can save your objects using the
CoreDataAdapter
just like any other object!License
Arcade is released under the MIT license. See LICENSE for details.