I have a NSDocument subclass and in the past I have overridden the this method:
override func restoreWindow(withIdentifier identifier: NSUserInterfaceItemIdentifier, state: NSCoder, completionHandler: @escaping (NSWindow?, Error?) -> Void) {
super.restoreWinow(withIdentifier: identifier, state: state, completionHandler: completionHandler)
}
But now when I do that I get the following error: "Method does not override any method from its superclass". I guess that's because it has been replaced with an async version. When I try this the compiler becomes happy:
override func restoreWindow(withIdentifier identifier: NSUserInterfaceItemIdentifier, state: NSCoder) async throws -> NSWindow {
try await super.restoreWindow(withIdentifier: identifier, state: state)
}
But at runtime this async version crashes with this stack trace:
Thread 1 Queue : com.apple.main-thread (serial)
#0 0x00007fff2ca3bdc7 in swift::ResolveAsSymbolicReference::operator()(swift::Demangle::__runtime::SymbolicReferenceKind, swift::Demangle::__runtime::Directness, int, void const*) ()
#1 0x00007fff2ca5e2dd in swift::Demangle::__runtime::Demangler::demangleSymbolicReference(unsigned char) ()
#2 0x00007fff2ca5b2a8 in swift::Demangle::__runtime::Demangler::demangleType(__swift::__runtime::llvm::StringRef, std::__1::function<swift::Demangle::__runtime::Node* (swift::Demangle::__runtime::SymbolicReferenceKind, swift::Demangle::__runtime::Directness, int, void const*)>) ()
#3 0x00007fff2ca415a4 in swift_getTypeByMangledNameImpl(swift::MetadataRequest, __swift::__runtime::llvm::StringRef, void const* const*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#4 0x00007fff2ca3ed6d in swift::swift_getTypeByMangledName(swift::MetadataRequest, __swift::__runtime::llvm::StringRef, void const* const*, std::__1::function<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>, std::__1::function<swift::TargetWitnessTable<swift::InProcess> const* (swift::TargetMetadata<swift::InProcess> const*, unsigned int)>) ()
#5 0x00007fff2ca3ef9b in swift_getTypeByMangledNameInContext ()
#6 0x00000001077f61f9 in __swift_instantiateConcreteTypeFromMangledName ()
#7 0x00000001078516a1 in _runTaskForBridgedAsyncMethod(_:) ()
#8 0x0000000107851213 in @objc Document.restoreWindow(withIdentifier:state:) ()
#9 0x00007fff231d32df in -[NSDocumentControllerPersistentRestoration loadedDocument:forAutoID:] ()
#10 0x00007fff231d6a3d in __89-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_2 ()
#11 0x00007fff231de927 in ___NSMainRunLoopPerformBlockInModes_block_invoke ()
#12 0x00007fff20448f12 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ ()
#13 0x00007fff20448dc3 in __CFRunLoopDoBlocks ()
#14 0x00007fff2044812c in __CFRunLoopRun ()
#15 0x00007fff2044704c in CFRunLoopRunSpecific ()
#16 0x00007fff2868fa83 in RunCurrentEventLoopInMode ()
#17 0x00007fff2868f6b6 in ReceiveNextEventCommon ()
#18 0x00007fff2868f583 in _BlockUntilNextEventMatchingListInModeWithFilter ()
#19 0x00007fff22c4fd72 in _DPSNextEvent ()
#20 0x00007fff22c4e545 in -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] ()
#21 0x00007fff22c40869 in -[NSApplication run] ()
#22 0x00007fff22c14a6c in NSApplicationMain ()
#23 0x0000000107838a84 in static NSApplicationDelegate.main() ()
#24 0x0000000107838a57 in static AppDelegate.$main() at /Users/jessegrosjean/Documents/github/BikeOutline/BikeMac/BikeMac/AppDelegate.swift:7
#25 0x000000010783a5e8 in main ()
#26 0x00007fff2036cf3d in start ()
I don't really understand the stack trace. What did I do wrong? How can I override "restoreWindow" while also using latest Swift?