ApplicationKit is a Swift-based library that provides a rich set of tools for managing and working with application state. Building upon AppState, it provides an additional layer of functionality to manage lifecycle notifications and state changes in applications.
- A streamlined approach to handling and observing different lifecycle notifications.
- A simplified interface to run closures only once from anywhere within the codebase.
- More to come...
-
Swift 5.7 or later
-
iOS 15.0 or later
-
watchOS 8.0 or later
-
macOS 11.0 or later
-
tvOS 15.0 or later
You can integrate ApplicationKit into your project using Swift Package Manager.
Once you have your Swift package set up, adding ApplicationKit as a dependency is as easy as adding it to the dependencies value of your Package.swift file.
dependencies: [
.package(url: "https://github.com/0xLeif/ApplicationKit.git", from: "0.1.0")
]
To handle various application states, override the necessary methods in your custom application class:
private class MyApplication: LifecyleApplication {
override var lifecycleNotifications: [LifecyleNotification] {
super.lifecycleNotifications + [
// Your additional lifecycle notifications
]
}
/// Gets called when application state becomes active
override func didBecomeActiveNotification(notification: Notification) {
// Custom code implementation
}
}
In your App initialization, promote your custom application class:
Application.promote(to: MyApplication.self)
Use ApplicationKit's .runOnce
feature to run a specific closure code once within the lifecycle of the application:
Application.runOnce { performExpensiveTaskHere() }
Pull requests are very welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
ApplicationKit is distributed under the MIT license. For more information, refer to the LICENSE file.