AppKit: NSViewController, Documents & SwiftUI Interop
NSViewController
class ProfileViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
// set up view hierarchy
}
}
// Conceptually analogous to UIViewController's lifecycle,
// adapted to macOS's windowed, mouse/keyboard-driven modelDocument-Based Apps
NSDocument provides a framework for document-based apps (like a text editor) -- handling file I/O, undo management, autosave, and multi-window document architecture out of the box.
Bridging to SwiftUI
struct LegacyEditorView: NSViewRepresentable {
func makeNSView(context: Context) -> LegacyEditor {
LegacyEditor()
}
func updateNSView(_ view: LegacyEditor, context: Context) {}
}
// Wraps an existing AppKit NSView so it can be used inside
// a modern SwiftUI view hierarchy -- common in hybrid codebasesWhy Teams Still Reach for AppKit
While SwiftUI has matured significantly, some advanced macOS behaviors -- complex text editing, specific window management, certain performance-critical drawing -- are still more directly and maturely supported through AppKit. Many real-world apps mix both: SwiftUI for newer UI, AppKit for legacy or advanced functionality via interop.
NSApplication: The App Lifecycle
NSApplication is the singleton coordinating the app's main event loop and lifecycle events (launch, termination), with an app delegate object commonly handling key callbacks -- the macOS counterpart to UIApplication on iOS.
Keep your own version of these notes — editable, searchable, and organised by your stack.
Start free