Third Challenge: Add a Window Controller


#1

I’ve had to take three weeks off from studying this book for training with my current job and am still trying to get back in the swing of this book. I’ve made some progress since my break, but I’m uncertain what is needed for this Challenge.

I’ve created the MainWindowController as directed, but can’t figure out how to "move the code for instantiating the view controller within it. I’ve deleted the ImageViewContoller.swift and .xib. I can get the flowViewTemplate or the columnViewTemplate to display by changing the code from flowWindowController.showWindow(self) to columnWindowController…, but can’t figure out the tabs, or if that was even the intent. I’ve made no changes to the SpeakLineViewController yet, so I won’t include it here.

AppDelegate.swift:

import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

func applicationDidFinishLaunching(_ aNotification: Notification) {
	
	let flowWindowController = MainWindowController()
	flowWindowController.contentViewController?.title = "Flow"
	flowWindowController.image = NSImage(named: NSImage.Name.flowViewTemplate)

	let columnWindowController = MainWindowController()
	columnWindowController.contentViewController?.title = "Column"
	columnWindowController.image = NSImage(named: NSImage.Name.columnViewTemplate)

	let speakLineViewController = SpeakLineViewController()
	speakLineViewController.title = "SpeakLine"

//		let tabViewController = NSTabViewController()
//		tabViewController.addChildViewController(flowViewController.contentViewController!)
//		tabViewController.addChildViewController(columnViewController.contentViewController!)
//		tabViewController.addChildViewController(speakLineViewController)

	flowWindowController.showWindow(self)
	
}

func applicationWillTerminate(_ aNotification: Notification) {
	// Insert code here to tear down your application
}

}

MainWindowController:

import Cocoa

class MainWindowController: NSWindowController {

@objc dynamic var image: NSImage?

override var windowNibName: NSNib.Name? {
	return NSNib.Name(rawValue: "MainWindowController")
}

override func windowDidLoad() {
    super.windowDidLoad()
}

}

Is this all there is to the Challenge? Or am I way off here and missing the point?

Thanks for any suggestions/help