Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLeif committed Dec 19, 2023
0 parents commit 43ae21f
Show file tree
Hide file tree
Showing 11 changed files with 624 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# These are supported funding model platforms

github: [0xLeif]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/
.netrc
Package.resolved
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Zach Eriksen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
32 changes: 32 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// swift-tools-version: 5.7

import PackageDescription

let package = Package(
name: "ApplicationKit",
platforms: [
.iOS(.v15),
.watchOS(.v8),
.macOS(.v11),
.tvOS(.v15)
],
products: [
.library(
name: "ApplicationKit",
targets: ["ApplicationKit"]
)
],
dependencies: [
.package(url: "https://github.com/0xLeif/AppState", from: "1.0.0")
],
targets: [
.target(
name: "ApplicationKit",
dependencies: ["AppState"]
),
.testTarget(
name: "ApplicationKitTests",
dependencies: ["ApplicationKit"]
)
]
)
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# ApplicationKit

ApplicationKit is a Swift-based library that provides a rich set of tools for managing and working with application state. Building upon [AppState](https://github.com/0xLeif/AppState), it provides an additional layer of functionality to manage lifecycle notifications and state changes in applications.

## Features

- A Lifecycle Management API that provides callback functions for significant events in the application lifecycle.
- A simplified interface to run closures only once from anywhere within the codebase.
- A streamlined approach to handling and observing different lifecycle notifications.
- Debugging support with file location attributes for effective lifecycle event tracking.
- More to come...

## Getting Started

### Requirements

- 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

### Installation

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.

```swift
dependencies: [
.package(url: "https://github.com/0xLeif/ApplicationKit.git", from: "0.1.0")
]
```

## Usage

To handle various application states, override the necessary methods in your custom application class:

```swift
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:

```swift
Application.promote(to: MyApplication.self)
```

Use ApplicationKit's `.runOnce` feature to run a specific closure code once within the lifecycle of the application:
```swift
Application.runOnce { performExpensiveTaskHere() }
```

## Contributing

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.

## License

ApplicationKit is distributed under the MIT license. For more information, refer to the LICENSE file.
1 change: 1 addition & 0 deletions Sources/ApplicationKit/AppState+export.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@_exported import AppState
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Foundation

extension LifecyleApplication {
/**
Represents a Lifecycle Notification event in the scope of `LifecyleApplication`.

This structure holds two properties:
- Selector: An action to be performed when the notification is observed.
- Notification.Name: The name of the notification event to be observed.
*/
public struct LifecyleNotification {
/// The action to be performed when the notification is observed.
public let selector: Selector

/// The name of the notification event to be observed.
public let name: Notification.Name

/**
Creates a `LifecyleNotification` with specified selector and notification name.

- Parameters:
- selector: The selector to be called when the notification is posted.
- name: The unique name of the notification to observe.
*/
public init(selector: Selector, name: Notification.Name) {
self.selector = selector
self.name = name
}
}
}
Loading

0 comments on commit 43ae21f

Please sign in to comment.