Portal 0.5.3

Portal 0.5.3

Maintained by Rolando Rodriguez.



 
Depends on:
Firebase/Core>= 0
Firebase/Firestore>= 0
Firebase/Auth>= 0
Firebase/Storage>= 0
Firebase/Analytics>= 0
 

Portal 0.5.3

  • By
  • rorodriguez116

Portal

Version License Platform

Portal is a simple abstraction layer of FirebaseFirestore and FirebaseAuth, it saves you a lot of work by automatycally parsing document snapshots into your data layer model by using generics at its core. Portal also allows you to use FirebaseAuth with a very easy to use API to sign-in & sign-up new users into FirebaseAuth and create its mirror representation into your database all done by PortalAuth while maintaining your specified data layer model.

Requirements

  • iOS 12.0+

Installation

Portal is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Portal'

Usage

Portal uses generics to identify what model it should use with your database path, to do so it uses generics at is core. Models used by Portal must conform to the PortalModel protocol.

Creating a Model

Let's declare a struct Pet which will be used as the base data layer model for this example.

PortalModel protocol only requirement is to declare a get only portalIdentifier variable. This variable will be used by Portal to create your model at a path that matches its unique identifier.

struct Pet: PortalModel {

    var id: String
    let name: String
    let age: Int
    
    var portalIdentifier: String {
        return id 
    }
}

Creating a Portal

To instantiate a new Portal you need to specify what model it will use and at what path in your database.

let portal = Portal<Pet>(path: "pets")

Portal Events

To use Portal's features you must access them by the .event function. In this example we'll use the .new event to create a new document with the structure of type Pet in your database in the path pets

let portal = Portal<Pet>(path: "pets")
let myPet = Pet(id: "MyPetID", name: "Monchi", age: 3)

portal.event(.new(myPet)) { (result) in
    switch result { 
        case .success: print("Success! Your data has been succesfully created")
        case .failure(let error): print(error)
    }
}

License

Portal is available under the MIT license. See the LICENSE file for more info.