No description
Find a file
2025-04-18 13:37:10 -07:00
Sources/NotificationTask First commit 2025-04-18 13:22:18 -07:00
Tests/NotificationTaskTests Add a readme 2025-04-18 13:37:10 -07:00
.gitignore First commit 2025-04-18 13:22:18 -07:00
Package.swift First commit 2025-04-18 13:22:18 -07:00
Readme.md Add a readme 2025-04-18 13:37:10 -07:00

NotificationTask

0 dependencies!

Overview

NotificationTask is

Installation

The only way to install this package is with Swift Package Manager (SPM). Please file a new issue or submit a pull-request if you want to use something else.

Supported Platforms

This package is supported on iOS 16.0+ and macOS 12.0+.

Xcode

When you're integrating this into an app with Xcode then go to your project's Package Dependencies and enter the URL https://github.com/samsonjs/NotificationTask and then go through the usual flow for adding packages.

Swift Package Manager (SPM)

When you're integrating this using SPM on its own then add this to the list of dependencies your Package.swift file:

.package(url: "https://github.com/samsonjs/NotificationTask.git", .upToNextMajor(from: "0.1.0"))

and then add "NotificationTask" to the list of dependencies in your target as well.

Usage

The simplest example uses a closure that receives the notification:

import NotificationTask

@MainActor class SimplestVersion {
    let task = NotificationTask(name: .NSCalendarDayChanged) { _ in
        print("The date is now \(Date.now)")
    }
}

Example using context to avoid reference cycles with self:

import NotificationTask

@MainActor class WithContext {
    var notificationTask: NotificationTask?

    init() {
        notificationTask = NotificationTask(name: .NSCalendarDayChanged, context: self) { _self, _ in
            _self.dayChanged()
        }
    }

    func dayChanged() {
        print("The date is now \(Date.now)")
    }
}

The closure is async so you can await in there if you need to.

License

Copyright © 2025 Sami Samhuri sami@samhuri.net. Released under the terms of the MIT License.