NSStoryboard has no member Name

I'm trying to select Main Storyboard via code but I cant.

import Cocoa

class QuotesViewController: NSViewController {

override func viewDidLoad() {
    // Do view setup here.


extension QuotesViewController {
// MARK: Storyboard instantiation
static func freshController() -> QuotesViewController {
    let storyboard = NSStoryboard(name: NSStoryboard.Name(rawValue: "Main"), bundle: nil)
    let identifier = NSStoryboard.SceneIdentifier(rawValue: "QuotesViewController")
    guard let viewcontroller = storyboard.instantiateController(withIdentifier: identifier) as? QuotesViewController else {
        fatalError("Why cant i find QuotesViewController? - Check Main.storyboard")
    return viewcontroller


I get the errors.

QuotesViewController.swift:25:45: Type 'NSStoryboard' has no member 'Name'
QuotesViewController.swift:27:26: Type 'NSStoryboard' has no member 'SceneIdentifier'

I understand why, but I'm following tutorial: https://www.raywenderlich.com/165853/menus-popovers-menu-bar-apps-macos.

I created QuotesViewController.swift as a cocoa class, inherited from NSViewController.

Why this happens?


This is not really a Swift question, so would have been better asked over at forums.developer.apple.com. But here's the answer…

In macOS 10.14, a number of APIs that took arbitrary strings — that were previously wrapped in a "type-safe" struct — were changed to not require wrapping, since the wrapping was just noise, and the type safety was pretty much illusory.

For compatibility, in 10.14 those types (like NSStoryboard.Name and NSStorboard.SceneIdentifier) were simply typealiased to String, which doesn't have a init(rawValue:) initializer.

Note that you never needed to use the rawValue: keyword. The following always worked:

    NSStoryboard(name: NSStoryboard.Name("main"), bundle: nil)

and that will still work in 10.14. Or, if you don't need backward compatibility, you can now write:

    NSStoryboard(name: "main", bundle: nil)

Edit: The error messages you got were actively misleading in this case, which is more of a Swift compiler bug than a frameworks bug. You might want to create a bug for Swift regarding the error messages.

Hello Quincey.

Thanks for your help. I'll report the bug.