繁体   English   中英

SwiftUI 崩溃 &lt;&lt; <opaque return type of view.contextmenu<a> (菜单项:)&gt;&gt;</opaque>

[英]SwiftUI crashing <<<opaque return type of View.contextMenu<A>(menuItems:)>>

我注意到一些崩溃,但我似乎真的找不到崩溃的任何具体原因,Xcode 也没有帮助我识别它。 QueryLogView.body.getterActiveInstance.swift:43都是代码中的空行,我不确定closure in closure in closure能告诉我什么。

也许它与报告中的第 3 行partial apply... 有人知道在哪里看吗?

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000101138968
Exception Note:  EXC_CORPSE_NOTIFY
Terminating Process: exc handler [23436]
Triggered by Thread:  0


Thread 0 name:
Thread 0 Crashed:
0   Pi-hole Remote                  0x0000000101138968 closure #5 in closure #1 in closure #1 in closure #2 in closure #1 in QueryLogView.body.getter + 316 (<compiler-generated>:0)
1   Pi-hole Remote                  0x00000001011388b8 closure #5 in closure #1 in closure #1 in closure #2 in closure #1 in QueryLogView.body.getter + 140 (QueryLogView.swift:0)
2   Pi-hole Remote                  0x000000010114b49c partial apply for thunk for @escaping @callee_guaranteed (@guaranteed [String]) -> (@out _ConditionalContent<AnyView, NavigationLink<<<opaque return type of View.contextMenu<A>(menuItems:)>>.0, Mod... + 24 (<compiler-generated>:0)
3   SwiftUI                         0x0000000188257740 ForEachChild.updateValue() + 1412 (ForEach.swift:1150)
4   SwiftUI                         0x00000001882588e4 partial apply for implicit closure #2 in implicit closure #1 in closure #1 in closure #1 in Attribute.init<A>(_:) + 32 (<compiler-generated>:0)
...
114 UIKitCore                       0x0000000182e5b958 UIApplicationMain + 2092 (UIApplication.m:5046)
115 Pi-hole Remote                  0x0000000100fd527c main + 68 (ActiveInstance.swift:43)
116 dyld                            0x0000000101a81aa4 start + 520 (dyldMain.cpp:879)

编辑:

这是QueryLogView中我使用.contextMenu的代码:

ForEach(filterQueries(array: queries.data), id: \.self) { query in
    NavigationLink(destination: QueryDetailView(query: query, instance: intIDtoInstance(Int(query.last ?? "1"))).environmentObject(self.state)) {
        QueryRow(headline: .all, instance: self.activeInstance, query: query)
            .contextMenu {
                Section {
                    Button(action: {
                        self.showSheet = .queriesToDomain(query[2])
                    }) {
                        Text("view_queries_to_domain")
                        Image(systemName: "doc.text.magnifyingglass")
                    }
                    Button(action: {
                        self.showSheet = .queriesToClient(query[3])
                    }) {
                        Text("view_queries_from_client")
                        Image(systemName: "doc.text.magnifyingglass")
                    }
                }
                Section {
                    if #available(iOS 14.0, *) {
                        if let domainURL = URL(string: "https://\(query[2])") {
                            Link(destination: domainURL, label: {
                                Text("visit_domain")
                                Image(systemName: "network")
                            })
                        }
                    }
                    Button(action: {
                        UIPasteboard.general.string = query[2]
                    }) {
                        Text("copy_domain")
                        Image(systemName: "doc.on.doc")
                    }
                    Button(action: {
                        UIPasteboard.general.string = query[3]
                    }) {
                        Text("copy_hostname_or_ip")
                        Image(systemName: "doc.on.doc")
                    }
                }
                Section {
                    Button(action: {
                        addToList(query)
                    }) {
                        Text("add_to_list_dots")
                        Image(systemName: "shield.lefthalf.fill")
                    }
                }
            }
    }.modify {
        if #available(iOS 15.0, *) {
            $0.swipeActions(edge: .leading, allowsFullSwipe: true) {
                Button {
                    addToList(query)
                } label: {
                    Label(queryToListTuple(query).list, systemImage: "shield.lefthalf.fill")
                }.tint(queryToListTuple(query).color)
            }
        } else {
            $0
        }
    }
    #if targetEnvironment(macCatalyst)
    .padding(.horizontal, -12)
    #endif
}

.modify用于具有基于 iOS 版本的条件修饰符:

extension View {
    func modify<T: View>(@ViewBuilder _ modifier: (Self) -> T) -> some View {
        return modifier(self)
    }
}

发现删除所有出现的.modify修复了崩溃。 不知道实际上出了什么问题,但它似乎可以解决它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM