-
Notifications
You must be signed in to change notification settings - Fork 28
Introduction
Pring makes it possible to make iOS App quickly with Swift.
The bottleneck of App development is to make REST API.Development of the REST API requires a lot of time-consuming work.
For example,
- Building a secure network
- Mapping to model
- Making Moc
- debug
Pring uses Firestore to solve it. The following sample code saves an Item in the DB with Pring.
let item: Item = Item()
item.name = "pring"
item.save()
If you make a new App,There is no need to build complicated REST APIs.It is possible to intuitively build a DB. Pring is designed for TypeSafe. It is possible to use all models for TypeSafe.
The database design philosophy of NoSQL and RDB is a totally different concept.Knowledge of RDB is useful, but it is not necessary.
The easiest way to try Pring is to define the model, save it and retrieve the data. Let's start with the project you finished installing.
First, make your Firebase available. Please download GoogleService-Info.plist
from Firebase and add it to the project. And add FirebaseApp.configure()
to the AppDelegate.swift
.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Initialize Firebase.
FirebaseApp.configure()
return true
}
Define a very simple model.
Pring
internally uses KVO. Please do not forget @objcMembers
and dynamic
.
import Foundation
import Pring
@objcMembers
class Item: Object {
dynamic var thumbnail: File?
dynamic var name: String?
}
Controlling the Model is very easy. First, you initialize the Item. Then set and save the data.
Here you save the Item with ViewController
.
import UIKit
import Pring
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let item: Item = Item()
item.name = "My new item"
item.save()
}
}
Go to the Firestore console and make sure that the Item is saved. The data is saved in this Path.
In
Pring
, versions are automatically assigned in consideration of data migration.
/version/1/item/:ITEM_ID
If you wish to assign an arbitrary ID, you can write as follows.
import UIKit
import Pring
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let item: Item = Item(id: "YOUR_ITEM_ID")
item.name = "My new item"
item.save()
}
}
Next, retrieve item data. To retrieve data, specify your Item ID and do it.
import UIKit
import Pring
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
Item.get("YOUR_ITEM_ID") { (item, error) in
if let error = error {
print(error)
return
}
print(item)
}
}
}
You can also retrieve multiple items by passing in a query.
import UIKit
import Pring
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
Item.query.dataSource().onCompleted { (snapshot, items) in
print(items)
}.get()
}
}