在NMAPositioningManager.h有這個常量:無法將類型的價值「NSNotification.Name」預期參數類型「NSKeyValueObservingOptions」
FOUNDATION_EXPORT NSString *const NMAPositioningManagerDidUpdatePositionNotification;
而且有我的代碼中迅速
NotificationCenter.addObserver(self, forKeyPath: "positionDidUpdate", options: NSNotification.Name.NMAPositioningManagerDidUpdatePosition, context: NMAPositioningManager.shared())
從Obj-C的這個例子中得到啓發:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(positionDidUpdate)
name:NMAPositioningManagerDidUpdatePositionNotification
object:[NMAPositioningManager sharedNMAPositioningManager]];
我對字段選項有一個錯誤:
NavigationViewController.swift:30:84: 不能類型的值 'NSNotification.Name' 轉換爲預期 參數類型 'NSKeyValueObservingOptions'
我必須鍵入有我的Swift代碼工作?
編輯:使用通知中心,而不是通知
只是爲了澄清。您的Objective C示例使用NSNotificationCenter,並且您的Swift代碼使用NSNotification。你想使用NSNotification還是NSNotificationCenter你想使用? – pbodsk
事實上,我必須使用NotificationCenter。我編輯我的答案,但我仍然有同樣的錯誤。 –