Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 501 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to debug "precondition failure" in Xcode?

#1
I'm building a SwiftUI App on Xcode 11 but is terminating immediately whenever I switch to a particular tab in the app.


Thing is, it always points to the `Application Delegate` file, which I think is not really the problem. I'm also getting this error in the console `precondition failure: invalid input index: 2` and that's it, no more additional details on what file, array, or function this error is coming from.

[![enter image description here][1]][1]

Is there any way in Xcode to isolate which is causing this problem?


[1]:
Reply

#2
In my case a "precondition failure" arose because I was requesting **AXUI** attributes from my application process on startup:


```swift
ForEach(
NSWorkspace.shared.runningApplications, // Maybe this only works with `.filter(...)`
id: \.processIdentifier
) { runningApp in

// if(runningApp != NSRunningApplication.current) { // This condition made it work for me

var appAXUI: AXUIElement = AXUIElementCreateApplication(runningApp.processIdentifier)
var element: AnyObject? = nil
AXUIElementCopyAttributeValue(appAXUI, "someAttr" as CFString, &element)
}
```
Reply

#3
I had the same problem. I just removed the random id (UUID) from the Identifiable and I fixed my crash
Reply

#4
Interesting I was using a NavigationView and changed it to a HSplitView and this crash started happening. As soon as I went back to the NavigationView this went away.
Reply

#5
In my case I used a TabView which was already inside a NavigationView. In my 4th tab I used a Namespace for animation and after adding Namespace animation it was crashing. I tried removing GeometryReader from TabView, it worked but had other consequences. I added extra NavigationView in 4th tab, it also worked but also had other consequences. But the most appropriate approach for me was removing a **Spacer()** in the 4th tav. Inside that View where I added Namespace animation there was a Spacer() in the button which push all the view up, I removed that and everything is fine now.
Reply

#6
I believe a bug has been filed with Apple

[To see links please register here]

that concerns GeometryReader crashes
in my case, I get a similar issue with a tabBar and the message "precondition failure: invalid input index: 2" when trying to use the GeometryReader as
```let w = geo.size.width```

I've tried using a guard statement around it... didn't work - maybe I don't grok GUARD.
Reply

#7
I've had this runtime error on simulators. In my case the problem was `NavigationBarItems`, I used it inside a wrong block as below:

NavigationView {
Group {
if something {

ScrollView {
...
}//ScrollView

} else {
...
}

}//group
.navigationBarItems(trailing: self.favoriteItem) // CRASH**
}

I moved the `NavigationBarItems` modifier and gave it to `ScrollView`:


NavigationView {
Group {
if something {

ScrollView {
...
}//ScrollView
.navigationBarItems(trailing: self.favoriteItem) // NO CRASH**

} else {
...
}

}//group
}
Reply

#8
I've run into this as well. I just want to share it in case someone finds it useful.

**SHORT ANSWER**

Wrapping my view into a `NavigationView` would raise the error. Using `.navigationViewStyle(StackNavigationViewStyle())` solved my problem.

**LONG ANSWER**

I had something like this:
```
NavigationView {
GeometryReader { proxy in
VStack {
Text("Dummy")
Spacer()
MyView() // CONTAINS HAS A GEOMETRY READER TOO
.frame(width: min(proxy.size.width, proxy.size.height),
height: min(proxy.size.width, proxy.size.height))
Spacer()
Text("Dummy")
}
}
}
```
And then, `MyView` had a `GeometryReader` inside too. The code as described would fail. If `NavigationView` was removed, the precondition failure wouldn't happen.

I used `.navigationViewStyle(StackNavigationViewStyle())` on `NavigationView` and that solved my issue.
Reply

#9
I had a TabView containing a view that used a List.
When switching tabs, my app was crashing with a similar error:
"precondition failure: attribute failed to set an initial value: 99"
This crashed:

var body: some View {
TabView {
ListView()
.tabItem {
Image(systemName: "list.dash")
Text("List")
}

Wrapping the ListView in a NavigationView fixed the crash.
I saw this use of NavigationView on "Swift Live – 007 SwiftUI TabView && List" by [Caleb Wells][1].


[To see links please register here]


This worked:

var body: some View {
TabView {
NavigationView { ListView() }
.tabItem {
Image(systemName: "list.dash")
Text("List")
}


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through