Swiftpack.co - netcosports/Astrarium as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by netcosports.
netcosports/Astrarium 5.1.1
iOS Library for global dispatchers
⭐️ 5
🕓 1 year ago
iOS
.package(url: "https://github.com/netcosports/Astrarium.git", from: "5.1.1")

Astrarium

Global dispatchers library

Version License Platform

Installation

pod 'Astrarium', '~> 5.0'

Main concept

The main idea behind this library is to solve the following problems:

  • Make AppDelegate implementation cleaner;
  • Stop providing interface over managers/handlers as singleton object;

The main concept of Astrarium is Service. A service is a statefull object in most of the cases. It has the same lifetime as the application. Access to these services is done by ServiceIdentifier using Dispatcher.

Initialization

To integrate Astrarium into your app, you need to be inherited your AppDelegate from Astrarium.AppDelegate:

public class AppDelegate: Astrarium.AppDelegate

Then you need to override services variable and return list of services ids:

  public override var services: [ServiceIds?] { return [
    .fabric,
    .firebase,
    .ui
    ]
  }

Service implementation

Service itself has access to any AppDelegate callbacks to perform any action your service needs. Here is the simple example of UI service:

extension ServiceIds {
  static let ui = ServiceIdentifier<UICoordinator>()
}

final class UICoordinator: AppService {
  func someFancyMethod() {}
  func setup(with launchOptions: LaunchOptions) {}
}

Then you can access instance of service:

Services[.ui]?.someFancyMethod()

GitHub

link
Stars: 5
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Swift 5.0
3 years ago
  • Support for Swift 5.0
  • Possibility to use custom AppService init

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics