{"id":1106,"url":"https://github.com/marty-suzuki/NoticeObserveKit","last_synced_at":"2025-08-06T13:32:26.408Z","repository":{"id":62449107,"uuid":"77420387","full_name":"marty-suzuki/NoticeObserveKit","owner":"marty-suzuki","description":"NoticeObserveKit is type-safe NotificationCenter wrapper.","archived":false,"fork":false,"pushed_at":"2024-06-30T18:27:37.000Z","size":96,"stargazers_count":150,"open_issues_count":0,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-06T03:10:51.671Z","etag":null,"topics":["ios","macos","notificationcenter","swift","tvos","type-safe","watchos"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marty-suzuki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-27T02:44:09.000Z","updated_at":"2024-06-30T18:27:24.000Z","dependencies_parsed_at":"2024-10-30T07:24:04.913Z","dependency_job_id":null,"html_url":"https://github.com/marty-suzuki/NoticeObserveKit","commit_stats":{"total_commits":23,"total_committers":1,"mean_commits":23.0,"dds":0.0,"last_synced_commit":"5e0e177338e2c2cab7213e72308aa88479e748c2"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty-suzuki%2FNoticeObserveKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty-suzuki%2FNoticeObserveKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty-suzuki%2FNoticeObserveKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marty-suzuki%2FNoticeObserveKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marty-suzuki","download_url":"https://codeload.github.com/marty-suzuki/NoticeObserveKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228905466,"owners_count":17989772,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","macos","notificationcenter","swift","tvos","type-safe","watchos"],"created_at":"2024-01-05T20:15:39.042Z","updated_at":"2024-12-09T14:30:51.768Z","avatar_url":"https://github.com/marty-suzuki.png","language":"Swift","funding_links":[],"categories":["EventBus","Libs","Events [🔝](#readme)"],"sub_categories":["Getting Started","Events","Other free courses","Linter"],"readme":"# NoticeObserveKit\n\n[![Version](https://img.shields.io/cocoapods/v/NoticeObserveKit.svg?style=flat)](http://cocoapods.org/pods/NoticeObserveKit)\n[![License](https://img.shields.io/cocoapods/l/NoticeObserveKit.svg?style=flat)](http://cocoapods.org/pods/NoticeObserveKit)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Platform](https://img.shields.io/cocoapods/p/NoticeObserveKit.svg?style=flat)](http://cocoapods.org/pods/NoticeObserveKit)\n\nNoticeObserveKit is type-safe NotificationCenter wrapper.\n\nSwift Concurrency (since macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0)\n\n```swift\nTask {\n    // .keyboardWillShow is a static property.\n    for try await keyboardInfo in NotificationCenter.default.nok.notifications(named: .keyboardWillShow) { \n        // In this case, keyboardInfo is UIKeyboardInfo type.\n        // It is inferred from a generic parameter of Notice.Name\u003cValue\u003e.\n        print(keyboardInfo)\n    }\n}\n```\n\nCombine (since macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0)\n\n```swift\n// .keyboardWillShow is a static property.\nNotificationCenter.default.nok.publisher(for: .keyboardWillShow)\n    .sink(\n        receiveCompletion: { _ in },\n        receiveValue: { keyboardInfo in\n            // In this case, keyboardInfo is UIKeyboardInfo type.\n            // It is inferred from a generic parameter of Notice.Name\u003cValue\u003e.\n            print(keyboardInfo)\n        }\n    )\n    .store(in: \u0026cancellables)\n```\n\nNoticeObserveKit original\n\n```swift\n// .keyboardWillShow is a static property.\nNotificationCenter.default.nok.observe(name: .keyboardWillShow) { keyboardInfo in\n    // In this case, keyboardInfo is UIKeyboardInfo type.\n    // It is inferred from a generic parameter of Notice.Name\u003cValue\u003e.\n    print(keyboardInfo)\n}\n// pool is Notice.ObserverPool.\n// If pool is released, Notice.Observes are automatically removed.\n.invalidated(by: pool)\n```\n\n## Usage\n\nFirst of all, you need to implement `Notice.Name\u003cT\u003e` like this.\n`T` is type of value in notification.userInfo.\n\n```swift\nextension Notice.Names {\n    static let keyboardWillShow = Notice.Name\u003cUIKeyboardInfo\u003e(\n        UIResponder.keyboardWillShowNotification\n    ) { userInfo in\n        // Implementing decode is only required if you want to use an already defined Notification.Name (e.g. UIResponder.keyboardWillShowNotification).\n        guard\n            let frame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue,\n            let duration = userInfo[UIKeyboardAnimationDurationUserInfoKey] as? TimeInterval,\n            let curve = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? UInt\n        else {\n            throw DecodeError()\n        }\n\n        return UIKeyboardInfo(\n            frame: frame,\n            animationDuration: duration,\n            animationCurve: UIViewAnimationOptions(rawValue: curve)\n        )\n    }\n}\n```\n\n## Customization\n\nIf you can post custom Notification like this.\n\n```swift\nextension Notice.Names {\n    // If you define your own custom Notification.Name, no implementation of decode is required.\n    static let navigationControllerDidShow = Notice.Name\u003cNavigationControllerContent\u003e(name: \"navigationControllerDidShow\")\n}\n\nlet content = NavigationControllerContent(viewController: viewController, animated: animated)\nNotificationCenter.default.nok.post(name: .navigationControllerDidShow, value: content)\n```\n\nYou can invalidate manually like this.\n\n```swift\nlet observer = NotificationCenter.default.nok.observe(name: .keyboardWillShow) { keyboardInfo in\n    print(keyboardInfo)\n}\nobserver.invalidate()\n```\n\n## Sample\n\n```swift\nimport UIKit\nimport NoticeObserveKit\n\nclass ViewController: UIViewController {\n    private let searchBar = UISearchBar(frame: .zero)\n    private lazy var keyboardNotificationTasks: [Task\u003cVoid, Error\u003e] = [\n        Task {\n            for try await value in NotificationCenter.default.nok.notifications(named: .keyboardWillShow) {\n                print(\"UIKeyboard will show = \\(value)\")\n            }\n        },\n        Task {\n            for try await value in NotificationCenter.default.nok.notifications(named: .keyboardWillHide) {\n                print(\"UIKeyboard will hide = \\(value)\")\n            }\n        }\n    ]\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        // Do any additional setup after loading the view, typically from a nib.\n        navigationItem.titleView = searchBar\n\n        configureObservers()\n    }\n\n    private func configureObservers() {\n        _ = keyboardNotificationTasks\n    }\n}\n```\n\n## Requirements\n\n- Swift 5\n- Xcode 15.0 or greater\n- iOS 10.0 or greater\n- tvOS 10.0 or greater\n- macOS 10.10 or greater\n- watchOS 3.0 or greater\n\n## Installation\n\n#### CocoaPods\n\nNoticeObserveKit is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"NoticeObserveKit\"\n```\n\n#### Carthage\n\nIf you’re using [Carthage](https://github.com/Carthage/Carthage), simply add\nNoticeObserveKit to your `Cartfile`:\n\n```\ngithub \"marty-suzuki/NoticeObserveKit\"\n```\n\nMake sure to add `NoticeObserveKit.framework` to \"Linked Frameworks and Libraries\" and \"copy-frameworks\" Build Phases.\n\n## Author\n\nmarty-suzuki, s1180183@gmail.com\n\n## License\n\nNoticeObserveKit is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarty-suzuki%2FNoticeObserveKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarty-suzuki%2FNoticeObserveKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarty-suzuki%2FNoticeObserveKit/lists"}