Hi, I am having a problem getting the VocalTextEdit app to save a document as per page 375. I have entered the code correctly but Xcode 9 (9A235) just produces screens and screens of error messages. I built it using Swift 4 and Swift 3.2 but it still doesn’t save.
Any suggestions would be gratefully received.
Thanks,
Stephen.
ibex10
October 13, 2017, 3:56am
2
If you post some of those error messages and your code, you will increase the likelyhood that someone will be able to diagnose the problem.
PS : Always post your code properly formatted. If you don’t know how to do this, it is described in this post.
Here is the Swift 4 code of my Document class for saving the document
class Document: NSDocument {
enum Error: Swift.Error, LocalizedError {
case UTF8Encoding
var failureReason: String? {
switch self {
case .UTF8Encoding: return "File cannot be encoded in UTF-8."
}
}
}
override class var autosavesInPlace: Bool {
return true
}
override func makeWindowControllers() {
// Returns the Storyboard that contains your Document window.
let storyboard = NSStoryboard(name: NSStoryboard.Name("Main"), bundle: nil)
let windowController = storyboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("Document Window Controller")) as! NSWindowController
self.addWindowController(windowController)
}
override func data(ofType typeName: String) throws -> Data {
let windowController = windowControllers[0]
let viewController = windowController.contentViewController as! ViewController
let contents = viewController.textView.string ?? ""
guard let data = contents.data(using: .utf8) else {
throw Document.Error.UTF8Encoding
}
return data
}
override func read(from data: Data, ofType typeName: String) throws {
// Insert code here to read your document
// from the given data of the specified type...
throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
}
}
and here are the error messages I am getting in Xcode
2017-10-13 16:38:37.616562+0100 VocalTextEdit[28779:2353376] warning: <NSRemoteView: 0x6100001223a0> determined it was necessary to configure <NSVBSavePanel: 0x100f1b630> to support remote view vibrancy
2017-10-13 16:38:37.636262+0100 VocalTextEdit[28779:2353376] -[NSVBSavePanel init] caught non-fatal NSObjectNotAvailableException ‘service com.apple.appkit.xpc.openAndSavePanelService failed to init an instance of NSSavePanelService on behalf of <NSRemoteView: 0x6100001223a0> due to {
callStackSymbols = (
0 CoreFoundation 0x00007fff8fe692cb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fffa4c8148d objc_exception_throw + 48
2 CoreFoundation 0x00007fff8fee7c3d +[NSException raise:format:] + 205
3 com.apple.appkit.xpc.openAndSavePanelService 0x00000001080da757 com.apple.appkit.xpc.openAndSavePanelService + 5975
4 AppKit 0x00007fff8d91eae6 -[NSViewController _loadViewIfRequired] + 75
5 AppKit 0x00007fff8d91ea51 -[NSViewController view] + 30
6 ViewBridge 0x00007fffa36afb90 -[NSViewServiceMarshal bootstrap:replyData:] + 3820
7 ViewBridge 0x00007fffa36b0d1f -[NSViewServiceMarshal bootstrap:withReply:] + 131
8 CoreFoundation 0x00007fff8fddcb8c invoking + 140
9 CoreFoundation 0x00007fff8fddca11 -[NSInvocation invoke] + 289
10 CoreFoundation 0x00007fff8fdf6196 -[NSInvocation invokeWithTarget:] + 54
11 ViewBridge 0x00007fffa36ef39a -[NSVB_ViewServiceImplicitAnimationDecodingProxy forwardInvocation:] + 222
12 CoreFoundation 0x00007fff8fddb54a forwarding + 538
13 CoreFoundation 0x00007fff8fddb2a8 CF_forwarding_prep_0 + 120
14 CoreFoundation 0x00007fff8fddcb8c invoking + 140
15 CoreFoundation 0x00007fff8fddca11 -[NSInvocation invoke] + 289
16 CoreFoundation 0x00007fff8fdf6196 -[NSInvocation invokeWithTarget:] + 54
17 ViewBridge 0x00007fffa36bd8a2 -[NSVB_QueueingProxy forwardInvocation:] + 327
18 CoreFoundation 0x00007fff8fddb54a forwarding + 538
19 CoreFoundation 0x00007fff8fddb2a8 CF_forwarding_prep_0 + 120
20 CoreFoundation 0x00007fff8fddcb8c invoking + 140
21 CoreFoundation 0x00007fff8fddca11 -[NSInvocation invoke] + 289
22 CoreFoundation 0x00007fff8fdf6196 -[NSInvocation invokeWithTarget:] + 54
23 CoreFoundation 0x00007fff8fddb54a forwarding + 538
24 CoreFoundation 0x00007fff8fddb2a8 CF_forwarding_prep_0 + 120
25 CoreFoundation 0x00007fff8fddcb8c invoking + 140
26 CoreFoundation 0x00007fff8fddca11 -[NSInvocation invoke] + 289
27 ViewBridge 0x00007fffa3712579 withHintInProgress + 487
28 ViewBridge 0x00007fffa37122b0 __deferNSXPCInvocationOntoMainThread_block_invoke_2 + 233
29 ViewBridge 0x00007fffa3696459 +[NSViewServiceApplication withHostPID:invoke:] + 46
30 ViewBridge 0x00007fffa3712173 __deferNSXPCInvocationOntoMainThread_block_invoke + 179
31 ViewBridge 0x00007fffa3711d67 __deferBlockOntoMainThread_block_invoke_2 + 544
32 CoreFoundation 0x00007fff8fdff17c CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12
33 CoreFoundation 0x00007fff8fddff84 __CFRunLoopDoBlocks + 356
34 CoreFoundation 0x00007fff8fddfac6 __CFRunLoopRun + 1878
35 CoreFoundation 0x00007fff8fddf114 CFRunLoopRunSpecific + 420
36 HIToolbox 0x00007fff8f33febc RunCurrentEventLoopInMode + 240
37 HIToolbox 0x00007fff8f33fcf1 ReceiveNextEventCommon + 432
38 HIToolbox 0x00007fff8f33fb26 _BlockUntilNextEventMatchingListInModeWithFilter + 71
39 AppKit 0x00007fff8d8d8a54 _DPSNextEvent + 1120
40 AppKit 0x00007fff8e0547ee -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2796
41 ViewBridge 0x00007fffa3697628 -[NSViewServiceApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 100
42 AppKit 0x00007fff8d8cd3db -[NSApplication run] + 926
43 AppKit 0x00007fff8d897e0e NSApplicationMain + 1237
44 libxpc.dylib 0x00007fffa57c08c7 _xpc_objc_main + 775
45 libxpc.dylib 0x00007fffa57bf2e4 xpc_main + 494
46 ViewBridge 0x00007fffa36c1c85 xpc_connection_handler + 0
47 ViewBridge 0x00007fffa369c316 NSViewServiceApplicationMain + 2985
48 com.apple.appkit.xpc.openAndSavePanelService 0x00000001080df6bb main + 208
49 libdyld.dylib 0x00007fffa5567235 start + 1
50 ??? 0x0000000000000001 0x0 + 1
);
name = NSInternalInconsistencyException;
reason = “+[NSOpenAndSavePanelService loadViewToService:isOpenPanel:appCentric:] : failed entitlements check”;
userInfo = “”;
}’ with backtrace (
0 CoreFoundation 0x00007fff8fe692cb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fffa4c8148d objc_exception_throw + 48
2 ViewBridge 0x00007fffa36d88ec -[NSRemoteView _advanceToConfigPhaseLegacy] + 2281
3 ViewBridge 0x00007fffa36d9189 -[NSRemoteView _viewServiceMarshalProxy:withDetailedErrorHandler:] + 233
4 ViewBridge 0x00007fffa36d956f -[NSRemoteView _viewServiceMarshalProxy:withErrorHandler:] + 76
5 ViewBridge 0x00007fffa36cb9b7 -[NSRemoteView bridge] + 241
6 ViewBridge 0x00007fffa36d507f -[NSRemoteView viewDidChangeBackingProperties] + 61
7 AppKit 0x00007fff8d8f531b _NSViewHierarchyDidChangeBackingProperties + 433
8 AppKit 0x00007fff8d8b746e -[NSView addSubview:] + 1242
9 AppKit 0x00007fff8d8f2c3b -[NSFrameView addSubview:] + 45
10 AppKit 0x00007fff8d8f2bff -[NSThemeFrame addSubview:] + 383
11 AppKit 0x00007fff8d95dfed -[NSThemeFrame _addKnownSubview:] + 38
12 AppKit 0x00007fff8d91a80f -[NSWindow setContentView:] + 647
13 AppKit 0x00007fff8db29e9a -[NSVBSavePanel init] + 344
14 AppKit 0x00007fff8db29d2d +[NSSavePanel newRemotePanel] + 190
15 AppKit 0x00007fff8db29a69 +[NSSavePanel _crunchyRawUnbonedPanel] + 96
16 AppKit 0x00007fff8e41540d -[NSDocument(NSDocumentSaving) _preparedSavePanelForOperation:] + 258
17 AppKit 0x00007fff8e415dff __104-[NSDocument(NSDocumentSaving) _runModalSavePanelForSaveOperation:delegate:didSaveSelector:contextInfo:]_block_invoke_2 + 323
18 AppKit 0x00007fff8dc401e2 -[NSDocument _commitEditingThenContinue:] + 474
19 AppKit 0x00007fff8dc3ffff -[NSDocument _commitEditingWithDelegate:didSomethingSelector:contextInfo:thenContinue:] + 92
20 AppKit 0x00007fff8e415cad __104-[NSDocument(NSDocumentSaving) _runModalSavePanelForSaveOperation:delegate:didSaveSelector:contextInfo:]_block_invoke + 342
21 AppKit 0x00007fff8e415b51 -[NSDocument(NSDocumentSaving) _runModalSavePanelForSaveOperation:delegate:didSaveSelector:contextInfo:] + 97
22 AppKit 0x00007fff8e4130d6 __86-[NSDocument(NSDocumentSaving) _saveDocumentWithDelegate:didSaveSelector:contextInfo:]_block_invoke_3 + 128
23 AppKit 0x00007fff8deb04d3 -[NSDocument(NSDocumentSerializationAPIs) _continueActivityUsingBlock:] + 320
24 AppKit 0x00007fff8e412eda __86-[NSDocument(NSDocumentSaving) _saveDocumentWithDelegate:didSaveSelector:contextInfo:]_block_invoke_2 + 486
25 AppKit 0x00007fff8dc401e2 -[NSDocument _commitEditingThenContinue:] + 474
26 AppKit 0x00007fff8dc3ffff -[NSDocument _commitEditingWithDelegate:didSomethingSelector:contextInfo:thenContinue:] + 92
27 AppKit 0x00007fff8e412ce5 __86-[NSDocument(NSDocumentSaving) _saveDocumentWithDelegate:didSaveSelector:contextInfo:]_block_invoke + 334
28 AppKit 0x00007fff8deaed6f -[NSDocument(NSDocumentSerializationAPIs) _performActivity:] + 1858
29 AppKit 0x00007fff8deb02e9 -[NSDocument(NSDocumentSerializationAPIs) performActivityWithSynchronousWaiting:usingBlock:cancellationHandler:] + 447
30 AppKit 0x00007fff8e412b91 -[NSDocument(NSDocumentSaving) _saveDocumentWithDelegate:didSaveSelector:contextInfo:] + 93
31 libsystem_trace.dylib 0x00007fffa57993a7 _os_activity_initiate_impl + 53
32 AppKit 0x00007fff8e056721 -[NSApplication(NSResponder) sendAction:to:from:] + 456
33 AppKit 0x00007fff8db29666 -[NSMenuItem _corePerformAction] + 324
34 AppKit 0x00007fff8db293d2 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 114
35 libsystem_trace.dylib 0x00007fffa57993a7 _os_activity_initiate_impl + 53
36 AppKit 0x00007fff8dbb2955 -[NSMenu performActionForItemAtIndex:] + 121
37 AppKit 0x00007fff8dbb28cc -[NSMenu _internalPerformActionForItemAtIndex:] + 94
38 AppKit 0x00007fff8dbb26f9 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 107
39 AppKit 0x00007fff8da69580 NSSLMMenuEventHandler + 986
40 HIToolbox 0x00007fff8f317d85 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1708
41 HIToolbox 0x00007fff8f316ff6 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 428
42 HIToolbox 0x00007fff8f32cd14 SendEventToEventTarget + 40
43 HIToolbox 0x00007fff8f3793e6 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 411
44 HIToolbox 0x00007fff8f3a49fb SendMenuCommandWithContextAndModifiers + 59
45 HIToolbox 0x00007fff8f3a49aa SendMenuItemSelectedEvent + 188
46 HIToolbox 0x00007fff8f3a487d ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2 + 96
47 HIToolbox 0x00007fff8f3a52b7 _ZL14MenuSelectCoreP8MenuData5PointdjPP13OpaqueMenuRefPt + 702
48 HIToolbox 0x00007fff8f3a4f66 _HandleMenuSelection2 + 460
49 AppKit 0x00007fff8da59368 _NSHandleCarbonMenuEvent + 239
50 AppKit 0x00007fff8dcd3702 _DPSEventHandledByCarbon + 54
51 AppKit 0x00007fff8e0540c5 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 963
52 AppKit 0x00007fff8d8cd3db -[NSApplication run] + 926
53 AppKit 0x00007fff8d897e0e NSApplicationMain + 1237
54 VocalTextEdit 0x0000000100002e2d main + 13
55 libdyld.dylib 0x00007fffa5567235 start + 1
56 ??? 0x0000000000000003 0x0 + 3
)
Can anyone help?
Thanks
From the error line above, it appears to me that your project may not have permissions to write into the user’s Documents folder. Take a look at the Capabilities panel for the project target then under “File Access” and insure that “Permissions & Access” is set to “Read & Write” for the “User Selected File”.
2 Likes
Hi BrianL3D1, thanks for that, it appears to be working now!
Stephen.
Hi,
You’re fix worked for me also. It’s a shame that this isn’t mentioned in this chapter, or at least not in the version I’m reading and following.