gpt4 book ai didi

ios - 尝试存档时自定义 NavigationStack 导致 `error: Segmentation fault: 11` 时的解决方法建议?

转载 作者:行者123 更新时间:2023-11-28 20:49:30 27 4
gpt4 key购买 nike

我目前正在使用自定义 NavigationStack 来控制我的导航,如 this article 中所建议的那样.

我能够成功运行构建、模拟、测试和分析,但是在运行存档时,Xcode 在完成之前抛出错误:Segmentation fault: 11

我已经通过反复试验将导致此错误的代码精确定位到 advance(_:) 方法(在 NavigationStack.swift 中)中的某个位置。

    func advance<V: View & Navigatable>(_ view: V) {
let item = NavigationItem(view)
viewStack.append( currentView )
withAnimation {
self.navigate = .forward
}
//>>>>>>>> HERE'S THE PROBLEM <<<<<<<<<
// ↓this↓ causes the Archive to fail.
currentView = item
}

我的环境:macOS Catalina - 版本 10.15.2,Xcode - 版本 11.3 (11C29)。(但是,我在从 macOSCatalina10.15.1 和 Xcode11.2 更新之前遇到了这个问题)

如果有帮助,我的其他源码如下:

SceneDelegate.swift:

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
...
let contentView = ContentView()//.environmentObject(UserData())
...
}

ContentView.swift:

struct ContentView: View {
//@EnvironmentObject var userData: UserData
var body: some View {
NavigationHost()
//.environmentObject(NavigationStack( --Commented out in Edit
// NavigationItem(view: AnyView( HomeView() ) --Commented out in Edit
.environmentObject(NavigationStack( HomeView() ))
.transition(.move(edge: .trailing))
//.environmentObject(userData)
}
}

NavigationHost.swift:

struct NavigationHost: View{
@EnvironmentObject var navigation: NavigationStack
//@EnvironmentObject var userData: UserData

var body: some View {
ZStack {
if self.navigation.navigate == .root {
self.navigation.currentView.view
//.environmentObject(self.userData)
.environmentObject(self.navigation)
}
else if self.navigation.navigate == .backward {
self.navigation.currentView.view
//.environmentObject(self.userData)
.environmentObject(self.navigation)
.transition(.move(edge: .leading))
}
if self.navigation.navigate == .forward {
self.navigation.currentView.view
//.environmentObject(self.userData)
.environmentObject(self.navigation)
.transition(.move(edge: .trailing))
}
...
}
}
}

NavigationStack.swift:

final class NavigationStack: ObservableObject {
enum Direction {
case root
case forward
case backward
}

@Published var viewStack: [NavigationItem] = []
@Published var currentView: NavigationItem
@Published var navigate: Direction = .root
@Published var turnOnCloseButton: Bool = false
@Published var turnOnBackButton: Bool = false

init<V: View & Navigatable>(_ view: V, description: String? = nil) {
let currentView = NavigationItem(view, description: description)
print("Navigation Stack Initialized")
self.currentView = currentView
}


func back(turnOffBack: Bool = true, turnOffClose: Bool = true) {
if turnOffBack { turnOnBackButton = false }
if turnOffClose { turnOnCloseButton = false }
if viewStack.count == 0 {
return
}
let last = viewStack.count - 1
currentView = viewStack[last]
withAnimation {
self.navigate = .backward
}
viewStack.remove(at: last)
}

func advance<V: View & Navigatable>(_ view: V) {
let item = NavigationItem(view)
viewStack.append( currentView )
withAnimation {
self.navigate = .forward
}
//>>>>>>>> HERE'S THE PROBLEM <<<<<<<<<
// ↓this↓ causes the Archive to fail.
currentView = item
}

func home() {
currentView = NavigationItem( HomeeView() )
viewStack.removeAll()
withAnimation {
self.navigate = .root
}
}

func bringToFront<V: View & Navigatable>(_ view: V) {
let item = NavigationItem(view)
viewStack = viewStack.filter { $0 != item }
//advance(view)
}

}

struct NavigationItem: Equatable{
var view: AnyView
let id: String = UUID().uuidString
var description: String

init< V: View & Navigatable >(_ view: V, description: String? = nil) {
self.view = AnyView(view)
if description==nil {
self.description = V.getDescription(view)()//"\(type(of: view))"
} else {
self.description = description!
}
}

static func == (lhs: NavigationItem, rhs: NavigationItem) -> Bool {
return lhs.description == rhs.description
}
}

protocol Navigatable {
var description: String { get }
}

extension Navigatable {
func getDescription() -> String {
return "\(type(of: self))"
}
}

我之前也问过关于 NavigationStack 的问题,但是 different issue .

我在 2 周前通过反馈助手发送了一份错误报告,但还没有得到任何结果。

我急于部署 TestFlight,非常感谢任何帮助!

编辑:这是存档失败的错误消息的一部分:

...
1. While running pass #41789 SILFunctionTransform "GenericSpecializer" on SILFunction "@$s8okan_app15NavigationStackC7advanceyyx7SwiftUI4ViewRzAA11NavigatableRzlFAA04NextH0V_Tg5".
for 'advance(_:)' (at /Users/myname/Downloads/my-project/my-project/Navigations/NavigationStack.swift:48:2)
0 swift 0x0000000112c88a63 PrintStackTraceSignalHandler(void*) + 51
1 swift 0x0000000112c88236 SignalHandler(int) + 358
2 libsystem_platform.dylib 0x00007fff6627942d _sigtramp + 29
3 libsystem_platform.dylib 0x0000000800000001 _sigtramp + 2581097457
4 swift 0x000000010f0cd08c swift::ReabstractionInfo::prepareAndCheck(swift::ApplySite, swift::SILFunction*, swift::SubstitutionMap, swift::OptRemark::Emitter*) + 572
5 swift 0x000000010f11fc5a swift::ReabstractionInfo::ReabstractionInfo(swift::ApplySite, swift::SILFunction*, swift::SubstitutionMap, swift::IsSerialized_t, bool, swift::OptRemark::Emitter*) + 122
6 swift 0x000000010f129cb5 swift::trySpecializeApplyOfGeneric(swift::SILOptFunctionBuilder&, swift::ApplySite, llvm::SmallSetVector<swift::SILInstruction*, 8u>&, llvm::SmallVectorImpl<swift::SILFunction*>&, swift::OptRemark::Emitter&) + 1653
7 swift 0x000000010f0027b1 (anonymous namespace)::GenericSpecializer::run() + 2673
8 swift 0x000000010ef7bfbe swift::SILPassManager::execute() + 4606
9 swift 0x000000010ebda9eb swift::CompilerInstance::performSILProcessing(swift::SILModule*, swift::UnifiedStatsReporter*) + 6379
10 swift 0x000000010e8d2f45 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 33925
11 swift 0x000000010e8c72b4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
12 swift 0x000000010e8547b3 main + 1219
13 libdyld.dylib 0x00007fff660807fd start + 1
14 libdyld.dylib 0x00000000000000d2 start + 2583165142
error: Segmentation fault: 11 (in target 'my-project' from project 'my-project')

最佳答案

要么你错过了一些代码,要么有一些错误:

NavigationStack 必须按如下方式调用:

var body: some View {
NavigationHost()
.environmentObject(NavigationStack(
HomeView() ))

//.environmentObject(userData)
}

关于ios - 尝试存档时自定义 NavigationStack 导致 `error: Segmentation fault: 11` 时的解决方法建议?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59306627/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com