Search code examples
swiftcocoanssplitviewcontroller

Programmatically changing the views inside NSSplitViewController


From the NSSplitViewController class reference at https://developer.apple.com/library/prerelease/mac/documentation/AppKit/Reference/NSSplitViewController_Class/index.html I understand that it has a property that is an array of objects oftype NSSplitViewItem. It also has methods to insert and remove NSSplitViewItem objects. However, there is no documentation for NSSplitViewItem. How do I create such an object?

I saw one example online:

let svi = NSSplitViewItem(viewController: vc) where vc is of type NSViewController

But found no Apple documentation at all. It almost seems like Apple wants developers not to programmatically add/remove NSSplitViewItem

Could someone tell me how to create a NSSplitViewItem?


Solution

  • Somehow no public documentation is available for NSSplitViewItem. But there is a little trick for scenarios like that. Type NSSplitViewItem in Xcode and then ⌘-click it. You will be able to see the 'header file' for NSSplitViewItem.

    There are multiple initializers available.

    Example:

    let item = NSSplitViewItem(viewController: self.viewController)
    splitViewController.addSplitViewItem(item)