通知中心固定在從swift3轉換swift4的轉換器已經改變NotificationCenter
以下觀點:如何swift4
NotificationCenter.default.addObserver(self, selector: #selector(myController.myFunction(_:)), name: NSNotification.Name.NSTextView.didChangeSelectionNotification, object: myNSTextView)
因此,由於selector
在.addObserver()
myFunction的現在有@objc在前面。現在編譯器正在抱怨,NSNotification.Name
類型沒有成員NSTextView
。這是轉換器製造的,而不是我。我很困惑。
如何解決這個問題?
更新。我發現這裏的資訊How to migrate NSWorkspace notifications to Swift 4?
所以我必須使用
NotificationCenter.default.addObserver(self, selector: #selector(myController.myFunction(_:)), name: NSTextView.didChangeSelectionNotification, object: myNSTextView)
觀看WWDC視頻「中的新增功能基金會」關於在斯威夫特的關鍵路徑,實現信息和你如何能做到用塊/關閉的觀察,而不是回調。 https://developer.apple.com/videos/play/wwdc2017/212/ –