【问题标题】:SwiftUI crashing <<<opaque return type of View.contextMenu<A>(menuItems:)>>SwiftUI 崩溃 <<<View.contextMenu<A>(menuItems:)>> 的不透明返回类型
【发布时间】:2021-12-23 10:03:17
【问题描述】:

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

或许与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)
    }
}

【问题讨论】:

  • Pi-hole Remote 是您的代码吗?
  • @Chris 是的。崩溃发生在 iOS 14 和 15 上,并且在我的端无法重现,因此我求助于日志 - 我似乎无法单独弄清楚日志发生了什么,因此我想知道是否有人可能会能够提供帮助!
  • 好的,你能发布任何与引用上下文菜单/QueryLogView.swift 的 pi-hole 相关的内容
  • @Chris 当然,我已经编辑了原始问题!
  • 不可能在没有minimal reproducible example 的情况下提供任何具体信息,但我会从id: \.self 开始——这在 SwiftUI 中可能会出现问题。有没有办法可以查询Identifiable,这样您就可以为他们使用真实的ID系统,而不是依赖id: \.self

标签: ios swift swiftui crash


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-23
    • 2015-05-23
    相关资源
    最近更新 更多