https://github.com/p-x9/scfnotification
📬 Swift wrapper for `CFNotificationCenter`
https://github.com/p-x9/scfnotification
corefoundation swift swiftpm
Last synced: about 1 year ago
JSON representation
📬 Swift wrapper for `CFNotificationCenter`
- Host: GitHub
- URL: https://github.com/p-x9/scfnotification
- Owner: p-x9
- License: mit
- Created: 2023-01-20T20:44:03.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-25T08:58:56.000Z (about 2 years ago)
- Last Synced: 2025-03-24T01:04:24.726Z (about 1 year ago)
- Topics: corefoundation, swift, swiftpm
- Language: Swift
- Homepage:
- Size: 33.2 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SCFNotification
Swift wrapper of `CFNotificationCenter`.
No more tedious type conversions using pointers.
[CFNotificationCenter](https://developer.apple.com/documentation/corefoundation/cfnotificationcenter-rkv)
## Usage
### CenterTypes
- local
(CFNotificationCenterGetLocalCenter)
- darwinNotify
(CFNotificationCenterGetDarwinNotifyCenter)
- distributed (macOS only)
(CFNotificationCenterGetDistributedCenter)
### import
```swift
import SCFNotification
```
### addObserver
```swift
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
```swift
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
```swift
SCFNotificationCenter
.removeObserver(center: .local,
observer: self,
name: .init("local.notification" as CFString)
)
/* or */
SCFNotificationCenter.local
.removeObserver(observer: self,
name: .init("local.notification" as CFString)
)
```