Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marty-suzuki/NoticeObserveKit
NoticeObserveKit is type-safe NotificationCenter wrapper.
https://github.com/marty-suzuki/NoticeObserveKit
ios macos notificationcenter swift tvos type-safe watchos
Last synced: 26 days ago
JSON representation
NoticeObserveKit is type-safe NotificationCenter wrapper.
- Host: GitHub
- URL: https://github.com/marty-suzuki/NoticeObserveKit
- Owner: marty-suzuki
- License: mit
- Created: 2016-12-27T02:44:09.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-30T17:14:03.000Z (over 4 years ago)
- Last Synced: 2024-03-29T19:44:30.741Z (about 2 months ago)
- Topics: ios, macos, notificationcenter, swift, tvos, type-safe, watchos
- Language: Swift
- Homepage:
- Size: 85 KB
- Stars: 150
- Watchers: 5
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-ios - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (EventBus / Getting Started)
- awesome-swift - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (Libs / Events)
- awesome-swift - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (Libs / Events)
- awesome-swifte - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (Libs / Events)
- awesome-swifty - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (Libs / Events)
- awesome-swift4 - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (Libs / Events)
- awesome-ios2 - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (EventBus / Other free courses)
- awesome-ios - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (EventBus / Other free courses)
- awesome-ios-star - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (EventBus / Getting Started)
- awesome-swiftxx - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (Libs / Events)
- awesome-ios - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (EventBus / Linter)
- awesome-ios - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (EventBus / Other free courses)
- fucking-awesome-swift - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (Libs / Events)
- awesome-swiftqq - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (Libs / Events)
- awesome-swift - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (Libs / Events)
- awesome-ios - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (EventBus / Linter)
- awesome-ios - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. :large_orange_diamond: (EventBus / Other free courses)
- awesome-iosx - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (EventBus / Getting Started)
- awesome-ios - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (EventBus / Linter)
- awesome-iosr - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (EventBus / Getting Started)
- learn.awesome-iOS - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. :large_orange_diamond: (EventBus)
- learn.awesome.ios - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (EventBus / Linter)
- awesome-ios - NoticeObserveKit - NoticeObserveKit is type-safe NotificationCenter wrapper that associates notice type with info type. (EventBus / Linter)
README
# NoticeObserveKit
[![Version](https://img.shields.io/cocoapods/v/NoticeObserveKit.svg?style=flat)](http://cocoapods.org/pods/NoticeObserveKit)
[![License](https://img.shields.io/cocoapods/l/NoticeObserveKit.svg?style=flat)](http://cocoapods.org/pods/NoticeObserveKit)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Platform](https://img.shields.io/cocoapods/p/NoticeObserveKit.svg?style=flat)](http://cocoapods.org/pods/NoticeObserveKit)NoticeObserveKit is type-safe NotificationCenter wrapper.
```swift
// .keyboardWillShow is a static property.
Notice.Center.default.observe(name: .keyboardWillShow) { keyboardInfo in
// In this case, keyboardInfo is UIKeyboardInfo type.
// It is inferred from a generic parameter of Notice.Name.
print(keyboardInfo)
}
// pool is Notice.ObserverPool.
// If pool is released, Notice.Observes are automatically removed.
.invalidated(by: pool)
```## Usage
First of all, you need to implement `Notice.Name` like this.
`T` is type of value in notification.userInfo.```swift
extension Notice.Names {
static let keyboardWillShow = Notice.Name(UIResponder.keyboardWillShowNotification)
}
```If you define custom object, you need to implement that with `NoticeUserInfoDecodable` protocol. To confirm this protocol, you must implement `init?(info: [AnyHashable : Any])` and `func dictionaryRepresentation() -> [AnyHashable : Any]`.
```swift
struct UIKeyboardInfo: NoticeUserInfoDecodable {
let frame: CGRect
let animationDuration: TimeInterval
let animationCurve: UIViewAnimationOptionsinit?(info: [AnyHashable : Any]) {
guard
let frame = (info[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue,
let duration = info[UIKeyboardAnimationDurationUserInfoKey] as? TimeInterval,
let curve = info[UIKeyboardAnimationCurveUserInfoKey] as? UInt
else {
return nil
}
self.frame = frame
self.animationDuration = duration
self.animationCurve = UIViewAnimationOptions(rawValue: curve)
}
}
```Usage for under v0.4.0 is [documents/v0_4_0](./documents/v0_4_0.md).
## Customization
If you can post custom Notification like this.
```swift
extension Notice.Names {
static let navigationControllerDidShow = Notice.Name(name: "navigationControllerDidShow")
}let content = NavigationControllerContent(viewController: viewController, animated: animated)
Notice.Center.default.post(name: .navigationControllerDidShow, value: content)
```You can invalidate manually like this.
```swift
let observer = Notice.Center.default.observe(name: .keyboardWillShow) { keyboardInfo in
print(keyboardInfo)
}
observer.invalidate()
```You can use vi NotificationCenter.
```swift
NotificationCenter.default.nok.observe(name: .keyboardWillShow) { keyboardInfo in
print(keyboardInfo)
}
.invalidated(by: pool)
```## Sample
```swift
import UIKit
import NoticeObserveKitclass ViewController: UIViewController {
private let searchBar = UISearchBar(frame: .zero)
private var pool = Notice.ObserverPool()override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
navigationItem.titleView = searchBarconfigureObservers()
}private func configureObservers() {
Notice.Center.default.observe(name: .keyboardWillShow) {
print("UIKeyboard will show = \($0)")
}.invalidated(by: pool)Notice.Center.default.observe(name: .keyboardWillHide) {
print("UIKeyboard will hide = \($0)")
}.invalidated(by: pool)
}
}
```## Requirements
- Swift 5
- Xcode 10.2 or greater
- iOS 10.0 or greater
- tvOS 10.0 or greater
- macOS 10.10 or greater
- watchOS 3.0 or greater## Installation
#### CocoaPods
NoticeObserveKit is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod "NoticeObserveKit"
```#### Carthage
If you’re using [Carthage](https://github.com/Carthage/Carthage), simply add
NoticeObserveKit to your `Cartfile`:```
github "marty-suzuki/NoticeObserveKit"
```Make sure to add `NoticeObserveKit.framework` to "Linked Frameworks and Libraries" and "copy-frameworks" Build Phases.
## Author
marty-suzuki, [email protected]
## License
NoticeObserveKit is available under the MIT license. See the LICENSE file for more info.