Getting "Swift/ContiguousArrayBuffer.swift:600: Fatal error: Index out of range" error when trying to nil a state #43
Replies: 6 comments
-
@olcayertas Is it possible to share a building project that reproduces the problem? Without that, I think the problem is here: internal func handleNewUserStore(_ id: String) {
guard let nc = getNavController() else { return }
guard let index = viewStore.userProfileStates.firstIndex (where: { $0.id == id }) else { return }
showUserProfile(
nc,
store: store.scope(
state: \.userProfileStates[index],
action: { .userProfileAction(id: id, action: $0) }
)
)
} Grabbing an element via the |
Beta Was this translation helpful? Give feedback.
-
Hi @stephencelis. Thank you for your response. Normally I wouldn't use the index but I have seen this approach in your This is even happening if there is only one child state and there is no other side effects that is running that changes the array. I have tried your suggestion and updated my code like this:
And this is also crashing: |
Beta Was this translation helpful? Give feedback.
-
I have also tried to get the state before calling
But this time my action to fetch content didn't update the UI. Can you please show me what is the correct way to have an array of child states and present child view controllers when a new state is added to array. Then remove the added state when the child view controller is dismissed? |
Beta Was this translation helpful? Give feedback.
-
With using Index or ID, I am able to show and communicate with my child view controller and clean it's state when user taps to back button using delayed clean action. The last thing remains is the clean all child states when user taps to one of the tab bar items and dismiss all the presented child view controllers. |
Beta Was this translation helpful? Give feedback.
-
OK, I think I have find the non-crashing way to do it:
But I am not sure if this is the best approach. |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for directing me to a solution that works for me! Love you guys! |
Beta Was this translation helpful? Give feedback.
-
Hi I have following case and state and I am trying to clear a state when user dismiss a view controller:
var userProfileStates: IdentifiedArrayOf<User.State> = .init()
But I am getting this error with all four of the approaches above:
Swift/ContiguousArrayBuffer.swift:600: Fatal error: Index out of range
These are the steps I produce the error:
If i set a break point before trying to nil the state I can see that the particular state is exist:
Lib version: 0.5.0
UPDATE:
Sending the clear action with a delay partially solved my problem:
This trick solves the problem when user taps to back button and clears out the particular state.
But if I push multiple user screens and tap a different tab bar item, all the sub view controllers are dismissed by tab bar and I should remove all the child states. For this one app still crashes.
Here is the stack trace for the case where user tapped to a tab bar item:
Thread 1 Queue : com.apple.main-thread (serial)
And this is the stack trace for TCA debug tread:
Thread 14 Queue : co.pointfree.ComposableArchitecture.DebugEnvironment (serial)
Beta Was this translation helpful? Give feedback.
All reactions