{"id":1102,"url":"https://github.com/100mango/SwiftNotificationCenter","last_synced_at":"2025-07-30T20:31:20.382Z","repository":{"id":62456604,"uuid":"58112650","full_name":"100mango/SwiftNotificationCenter","owner":"100mango","description":"A Protocol-Oriented NotificationCenter which is type safe, thread safe and with memory safety","archived":false,"fork":false,"pushed_at":"2019-06-11T09:07:20.000Z","size":1164,"stargazers_count":639,"open_issues_count":4,"forks_count":44,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-12-01T07:42:57.410Z","etag":null,"topics":[],"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/100mango.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-05T07:26:45.000Z","updated_at":"2024-11-26T22:31:42.000Z","dependencies_parsed_at":"2022-11-02T00:15:19.054Z","dependency_job_id":null,"html_url":"https://github.com/100mango/SwiftNotificationCenter","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/100mango%2FSwiftNotificationCenter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/100mango%2FSwiftNotificationCenter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/100mango%2FSwiftNotificationCenter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/100mango%2FSwiftNotificationCenter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/100mango","download_url":"https://codeload.github.com/100mango/SwiftNotificationCenter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228179198,"owners_count":17881141,"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":[],"created_at":"2024-01-05T20:15:38.950Z","updated_at":"2024-12-04T19:32:54.972Z","avatar_url":"https://github.com/100mango.png","language":"Swift","funding_links":[],"categories":["EventBus"],"sub_categories":["Getting Started","Other free courses","Linter"],"readme":"\n\u003cp align=\"center\"\u003e \u003cimg src=\"logo.png\" /\u003e\n\u003cbr\u003e\n\n ![](http://img.shields.io/badge/Swift-5.0-blue.svg)\n\n\n\nA Protocol-Oriented NotificationCenter which is type safe, thread safe and with memory safety.\n\n- Type Safe\n\n\tNo more `userInfo` dictionary and Downcasting, just deliver the concrete type value to the observer.\n\t\n- Thread Safe\n\n\tYou can `register`, `notify`, `unregister` in any thread without crash and data corruption.\n\t\n- Memory Safety\n\n\t `SwiftNotificationCenter` store the observer as a zeroing-weak reference. No crash and no need to `unregister` manually.\n\t\t\nIt's simple, safe, lightweight and easy to use for `one-to-many` communication.\n\n\n## Usage\n\nDefine protocol and observer:\n\n~~~swift\nprotocol Update {\n    func updateTitle(title: String)\n}\n\nextension ViewController: Update {\n  func updateTitle(title: String) {\n  \t\tself.titleLabel.text = title\n  }\n}\nlet vc = ViewController()\n~~~\n\nRegister:\n\n~~~swift\nBroadcaster.register(Update.self, observer: vc)\n~~~\n\nBroadcast:\n\n~~~swift\nBroadcaster.notify(Update.self) {\n    $0.updateTitle(\"new title\")\n}\n~~~\n\nUnregister:\n\n~~~swift\nBroadcaster.unregister(Update.self, observer: self)\n~~~\n\n\u003cbr\u003e\n\nCompare with `NSNotificationCenter` :\n\nFor example, handle `UIKeyboardWillShowNotification`\n\n~~~swift\n@objc func handleKeyboardNotification(notification: NSNotification) {\n    guard notification.name == NSNotification.Name.UIKeyboardWillShow\n        else { return }\n    \n    guard let beginFrame = (notification\n        .userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue\n        else { return }\n    \n    guard let endFrame = (notification\n        .userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue\n        else { return }\n    // use beginFrame, endFrame\n}\n~~~\n\n`SwiftNotificationCenter` way:\n\n~~~swift\n/*\nIf you want to observe the system built in notifications like this.\nYou can declare a protocol and the relevant method, and use a singleton as a mediator to observe system's notification, then notify our observers.\nPlease check the refactor example in SwiftNotificationCenterExample Project.\n*/\nfunc UIKeyboardWillShow(beginFrame: CGRect, endFrame: CGRect) {\n}\n~~~\n\n## Installation\n\nCocoaPods:\n\n~~~\npod 'SwiftNotificationCenter'\n~~~\n\nCarthage:\n\n~~~\ngithub \"100mango/SwiftNotificationCenter\"\n~~~\n\nManually: \n\nJust copy source files in the SwiftNotificationCenter folder into your project.\n\n\n## License\n\n`SwiftNotificationCenter` is under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F100mango%2FSwiftNotificationCenter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F100mango%2FSwiftNotificationCenter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F100mango%2FSwiftNotificationCenter/lists"}