Posts

Post not yet marked as solved
2 Replies
769 Views
I tried to wrap NSTextView using TextKit 2 into NSViewRepresentable, so I can use it on SwiftUI. But when I try to access textLayoutManager and textContentStorage, they are always nil import Foundation import SwiftUI import Cocoa struct Editor_macOS: NSViewRepresentable {     func makeNSView(context: Context) -> NSScrollView {         let textContainer = NSTextContainer(size: .zero)         context.coordinator.textLayoutManager.textContainer = textContainer         let textView = NSTextView(frame: .zero, textContainer: textContainer)         context.coordinator.textView = textView                  if let docURL = Bundle.main.url(forResource: "menu", withExtension: "rtf") {             do {                 print(textView.textLayoutManager) //                try textView.textContentStorage!.textStorage?.read(from: docURL, documentAttributes: nil, error: ())             } catch {                 // Could not read menu content.             }         }                  textView.isRichText = false         textView.font = NSFont.monospacedSystemFont(ofSize: NSFont.systemFontSize, weight: .regular)         textView.autoresizingMask = [.width]         textView.translatesAutoresizingMaskIntoConstraints = true         textView.isVerticallyResizable = true         textView.isHorizontallyResizable = false         let scrollView = NSTextView.scrollableTextView()         scrollView.hasVerticalScroller = true         scrollView.drawsBackground = false         context.coordinator.scrollView = scrollView         return scrollView     }          func updateNSView(_ nsView: NSScrollView, context: Context) {     }          class Coordinator: NSObject {         var parent: Editor_macOS         var textView: NSTextView?         let textLayoutManager = NSTextLayoutManager()         init(_ parent: Editor_macOS) {             self.parent = parent         }     }          func makeCoordinator() -> Editor_macOS.Coordinator {         Editor_macOS.Coordinator(self)     }          typealias NSViewType = NSScrollView } Does anyone have an ideal why is it?
Posted Last updated
.
Post not yet marked as solved
1 Replies
1.4k Views
I have written a custom protocol, which is a subclass of `URLProtocol` but somehow i got a crash with following info:EXC_BAD_ACCESScom.apple.CFNetwork.CustomProtocols (15)#0 0x0000000183fbad8c in URLConnectionInstanceData::withWorkQueueAsync(void () block_pointer) const ()#1 0x0000000183fcc3f8 in URLConnectionLoader_Classic::protocolDidReceiveResponse(_CFURLResponse*) ()#2 0x0000000183e6b4b0 in -[__NSCFURLProtocolClient_NS withCustomProtocolScheduling:] ()#3 0x0000000183e6bb98 in -[__NSCFURLProtocolClient_NS URLProtocol:didReceiveResponse:cacheStoragePolicy:] ()#4 0x00000001056f3f34 in SecureURLProtocol.gotProgressCall(request:force:) ()#5 0x00000001056f489c in SecureURLProtocol.requestFinishedLoading(request:) ()#6 0x00000001056f2de8 in SecureURLProtocol.startLoading() ()#7 0x00000001056f30d8 in @objc SecureURLProtocol.startLoading() ()#8 0x0000000183e716f4 in ___ZN16CFURLProtocol_NS28_protocolInterface_startLoadEPK20_CFCachedURLResponse_block_invoke ()#9 0x000000010652545c in _dispatch_client_callout ()#10 0x0000000106531b74 in _dispatch_block_invoke_direct ()#11 0x0000000184091f94 in RunloopBlockContext::_invoke_block(void const*, void*) ()#12 0x00000001837a7900 in CFArrayApplyFunction ()#13 0x0000000184091e58 in RunloopBlockContext::perform() ()#14 0x00000001840931d8 in MultiplexerSource::perform() ()#15 0x0000000184092f38 in MultiplexerSource::_perform(void*) ()#16 0x000000018388a2e8 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()#17 0x000000018388a268 in __CFRunLoopDoSource0 ()#18 0x0000000183889af0 in __CFRunLoopDoSources0 ()#19 0x00000001838876c8 in __CFRunLoopRun ()#20 0x00000001837a7fb8 in CFRunLoopRunSpecific ()#21 0x00000001840913b8 in _privateRunloopEmulationSet(void*) ()#22 0x000000018350c31c in _pthread_body ()#23 0x000000018350c1e8 in _pthread_start ()#24 0x000000018350ac28 in thread_start ()Does anyone know what could be the source of this issue?Thanks
Posted Last updated
.