In Objective-C, a custom notification is just a plain NSString, but it's not obvious in the WWDC version of Swift 3 just what it should be.
相关问题
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
- Get the NSRange for the visible text after scroll
- UIPanGestureRecognizer is not working in iOS 13
- What does a Firebase observer actually do?
相关文章
- Using if let syntax in switch statement
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
- How can I vertically align my status bar item text
- Adding TapGestureRecognizer to UILabel in Swift
- Attempt to present UIAlertController on View Contr
- Swift - Snapshotting a view that has not been rend
I did my own implementation mixing things from there and there, and find this as the most convenient. Sharing for who any that might be interested:
Easier way:
This is just reference
You can add a custom initializer to NSNotification.Name
Usage:
The advantage of using enums is that we get the compiler to check that the name is correct. Reduces potential issues and makes refactoring easier.
For those who like using enums instead of quoted strings for notification names, this code does the trick:
Then you can use it like this:
Though unrelated to the question, the same can be done with storyboard segues, to avoid typing quoted strings:
Then, on your view controller, call it like:
There is a cleaner (I think) way to achieve it
And then you can use it like this