Reputation: 17705
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'
What i have to type to have my Swift Code working ?
EDIT : using NotificationCenter instead of Notification
Upvotes: 3
Views: 6409
Reputation: 629
UPDATED WITH SWIFT 5.4
NotificationCenter.default.addObserver(self,
selector: #selector(doThisWhenNotify),
name: NSNotification.Name("notificationKey"),
object: nil)
Upvotes: 3
Reputation: 644
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())
Upvotes: 4