Swiftpack.co - p-x9/SCFNotification as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by p-x9.
p-x9/SCFNotification 0.0.6
📬 Swift wrapper for `CFNotificationCenter`
⭐️ 3
🕓 1 year ago
.package(url: "https://github.com/p-x9/SCFNotification.git", from: "0.0.6")

SCFNotification

Swift wrapper of CFNotificationCenter. No more tedious type conversions using pointers.

CFNotificationCenter

Usage

CenterTypes

  • local (CFNotificationCenterGetLocalCenter)
  • darwinNotify (CFNotificationCenterGetDarwinNotifyCenter)
  • distributed (macOS only) (CFNotificationCenterGetDistributedCenter)

import

import SCFNotification

addObserver

SCFNotificationCenter
            .addObserver(center: .local,
                         observer: self,
                         name: .init("local.notification" as CFString),
                         suspensionBehavior: .deliverImmediately) { center, `self`, name, object, userInfo in
                print(center, name, object, userInfo)
            }

/*  or  */

SCFNotificationCenter.local
            .addObserver(observer: self,
                         name: .init("local.notification" as CFString),
                         suspensionBehavior: .deliverImmediately) { center, `self`, name, object, userInfo in
                self?.show()
                print(center, name, object, userInfo)
            }

postNotification

SCFNotificationCenter
            .postNotification(center: .local,
                              name: .init("local.notification" as CFString),
                              userInfo: [:] as CFDictionary,
                              deliverImmediately: true
            )

/*  or  */

SCFNotificationCenter.local
            .postNotification(name: .init("local.notification" as CFString),
                              userInfo: [:] as CFDictionary,
                              deliverImmediately: true
            )

removeObserver

SCFNotificationCenter
            .removeObserver(center: .local,
                            observer: self,
                            name: .init("local.notification" as CFString)
            )

/*  or  */

SCFNotificationCenter.local
            .removeObserver(observer: self,
                            name: .init("local.notification" as CFString)
            )

GitHub

link
Stars: 3
Last commit: 4 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

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