Using Xcode 12 and for a macOS program.
I created a test project to run down this error. The test app simply has a window controller/view controller that I added a search tool bar item to. While running searchFieldToolbarItem.view line of code crashes due to nil value. The class hierarchy from the debugger has the baseNSObject at the third level where as I was expecting this a the first level. I have this same code in another app and in debugger it shows baseNSObject at the top level. What am I missing and any ideas how to fix this?
I created a test project to run down this error. The test app simply has a window controller/view controller that I added a search tool bar item to. While running searchFieldToolbarItem.view line of code crashes due to nil value. The class hierarchy from the debugger has the baseNSObject at the third level where as I was expecting this a the first level. I have this same code in another app and in debugger it shows baseNSObject at the top level. What am I missing and any ideas how to fix this?
Code Block import Cocoa var custSearchField: NSSearchField = NSSearchField() class ViewController: NSViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override var representedObject: Any? { didSet { // Update the view, if already loaded. } } override func viewWillAppear() { guard let toolbar = self.view.window?.toolbar else { return } guard let searchFieldToolbarItem = toolbar.items.last else { return } custSearchField = (searchFieldToolbarItem.view as? NSSearchField)! } }