Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot convert value of type 'NSNotification.Name' to expected argument type 'NSKeyValueObservingOptions'

In NMAPositioningManager.h there is this const :

FOUNDATION_EXPORT NSString *const NMAPositioningManagerDidUpdatePositionNotification;

And there is my code in swift

NotificationCenter.addObserver(self, forKeyPath: "positionDidUpdate", options: NSNotification.Name.NMAPositioningManagerDidUpdatePosition, context: NMAPositioningManager.shared())

Inspired from this example in Obj-C:

[[NSNotificationCenter defaultCenter] addObserver:self
 selector:@selector(positionDidUpdate)
 name:NMAPositioningManagerDidUpdatePositionNotification
 object:[NMAPositioningManager sharedNMAPositioningManager]];

I have an error with the field option :

NavigationViewController.swift:30:84: Cannot convert value of type 'NSNotification.Name' to expected argument type 'NSKeyValueObservingOptions'

enter image description here

What i have to type to have my Swift Code working ?

EDIT : using NotificationCenter instead of Notification

like image 675
Kevin ABRIOUX Avatar asked Jan 17 '26 23:01

Kevin ABRIOUX


1 Answers

You should call the addObserver.. method on default singleton It should be:

NotificationCenter.default.addObserver(self, selector: #selector(positionDidUpdate), name: NSNotification.Name.NMAPositioningManagerDidUpdatePosition, object: NMAPositioningManager.shared())
like image 106
Octaviano Putra Avatar answered Jan 19 '26 18:01

Octaviano Putra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!