Cely#

Cely was made to help handle user credentials and handling login with ease. Below you will find documentation for Cely's Framework. Please do not hesitate to open an issue if something is unclear or is missing.

setup(_:)#

Configuration method for Cely.

Declaration

static func setup(
  with window: UIWindow?,
  forModel model: CelyUser,
  requiredProperties: [CelyProperty],
  withOptions options: [CelyOptions : Any?]?
) -> Void

Example

Cely.setup(with: window, forModel: User(), requiredProperties:[.token], withOptions:[
  .homeViewController: UIHostingController(rootView: HomeContentView()),
  .loginCompletionBlock: { (username: String, password: String) in
      if username == "username" && password == "password" {
          // ...
          Cely.changeStatus(to: .loggedIn)
      }
  }
])

Parameters

Parameter Type Required? Description
window UIWindow window of your application.
forModel CelyUser The model Cely will be using to store data.
requiredProperties [CelyProperty] The properties that cely tests against to determine if a user is logged in.
Default value: empty array.
options [CelyOptions: Any] Dictionary of CelyOptions to pass in additional customizations to Cely.




changeStatus(_:)#

Transition application between a loggedIn/loggedOut states.

Declaration

static func changeStatus(to status: CelyStatus)

Example

changeStatus(to: .loggedOut)

Parameters

Parameter Type Required? Description
status CelyStatus .loggedIn or .loggedOut




get(_:) -> Any?#

Retrieve data from store.

Declaration

static func get(key: String, fromStorage store: CelyStorageProtocol) -> Any?

Example

let username = Cely.get(key: "username")

Parameters

Parameter Type Required? Description
key String The key to the value you want to retrieve.
store CelyStorageProtocol no Storage Cely will be using. Defaulted to CelyStorage




save(_:) -> Result#

Saves data in store.

Declaration

static func save(
  _ value: Any?,
  forKey key: String,
  toStorage store: CelyStorageProtocol,
  securely secure: Bool,
  persisted persist: Bool
) -> Result<Void, Error>

Example

Cely.save("test@email.com", forKey: "email")
Cely.save("testUsername", forKey: "username", persisted: true)
Cely.save("token123", forKey: "token", securely: true)

Parameters

Parameter Type Required? Description
value Any? The value you want to save to storage.
key String The key to the value you want to save.
store CelyStorageProtocol no Storage Cely will be using. Defaulted to CelyStorage.
secure Bool no If you want to store the value securely.
persist Bool no Keep data after logout.




currentLoginStatus() -> CelyStatus#

Returns CelyStatus of the current user.

Declaration

static func currentLoginStatus(
  requiredProperties properties: [CelyProperty],
  fromStorage store: CelyStorageProtocol
) -> CelyStatus

Example

let status = Cely.currentLoginStatus()

Parameters

Parameter Type Required? Description
properties CelyProperty no Array of required properties that need to be in store.
store CelyStorageProtocol no Storage Cely will be using. Defaulted to CelyStorage




logout(_:)#

Convenience method to logout user and remove all non-persisted data.

Declaration

static func logout(useStorage store: CelyStorageProtocol = store) -> Result<Void, Error>

Example

Cely.logout()

Parameters

Parameter Type Required? Description
store CelyStorageProtocol no Storage Cely will be using. Defaulted to CelyStorage




isLoggedIn() -> Bool#

Returns boolean whether or not the user is logged in

Declaration

static func isLoggedIn() -> Bool

Example

if Cely.isLoggedIn() {
  print("is logged in")
}