https://github.com/remirobert/notificationobserver
NotificationObserver
https://github.com/remirobert/notificationobserver
Last synced: about 1 month ago
JSON representation
NotificationObserver
- Host: GitHub
- URL: https://github.com/remirobert/notificationobserver
- Owner: remirobert
- Created: 2016-09-19T08:52:04.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-19T09:58:42.000Z (over 9 years ago)
- Last Synced: 2025-01-11T06:13:17.246Z (over 1 year ago)
- Language: Swift
- Size: 13.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NotificationObserver
**NotificationObserver** is the *NSNotificationCenter* wrapper for **Swift3** 🎉.
This will make sure the adding and removing observers to the notification center is automatically managed.
Adding is as simple as creating an object, and removing is as simple as deallocing that object.
#Example
How to declare your notification : (**NotificationApp.swift**)
```Swift
import NotificationObserver
enum NotificationApp {
case Name
case UUID
}
extension NotificationApp: NotificationProtocol {
var name: String {
get {
switch self {
case .Name:
return "name"
case .UUID:
return "uuid"
}
}
}
}
```
Using observe a notification :
```Swift
import NotificationObserver
class ViewController: UIViewController {
//the observer will be removed automatically when your UIViewController will be deallocated
//if you don't use a reference, abviously the observer will be directly deallocated
private var obs: NotificationObserver!
override func viewDidLoad() {
super.viewDidLoad()
self.obs = NotificationObserver(notification: NotificationApp.UUID, block: { uuid in
guard let uuid = uuid else {
return
}
print("suuid : \(uuid)")
})
}
}
```
Post a notification somewhere :
```Swift
NotificationApp.UUID.post(UUID().uuidString)
```