iOS Apprentice 4th Edition fatalError("Should never get here")

Could you please help me with this error? Can’t understand what the problem is :expressionless::expressionless:!
Checked code with SourceCode files all is the same.

UPD. When I run project form SourceCode folder I’ve got the same error. Maybe problem is in iOS Simulator or in Settings?
Because I’ve checked code more times all is the same and there is no errors on compilation.

There is no code error as such - you are just hitting a bit of code that was not supposed to be executed. Just clarifying in case that wasn’t clear :slight_smile:

The question is why you’re hitting that particular block of code. Since, according to the information given in your post, this is for the 4th edition of the book and you appear to be running on Xcode 9, it is possible that there might be some issue due to Swift changes or something? I’d have to try running that particular version of the code under Xcode 9.

Have you tried the latest version of the code (from 6th edition of the book) to see if that shows the same issue?

Thanks for reply :slightly_smiling_face: Yeah, I’m using Xcode 9 but everything works great until, as I remember, I merge branch with refactoring changes to master branch. Error is very strange and I still cant fix this :expressionless:

It is probably an issue with the search.state not being set correctly or not being initialized since I believe search.state should be set to some initial value to prevent you from getting to the fatalError branch of the code. I don’t have my machine or Xcode handy to test it out but what I’d suggest is that you search for search.state in your code and see how that value is initialized and how it changes as the code execution proceeds …

Yeah, I also think the problem is in search.state but I checked code and everything is the same as in SourceCode folder. Today will repeat refactoring part from older branch.

OK, let me know if that doesn’t help. I won’t get my computer back till later today but when I do, I will see if I can find the 4th edition source code and see what happens if I compile it. If I can’t get the 4th edition source code, or can’t reproduce the issue with the source code, are you in a position to send me the project you are working on if you can’t find the isuse? Then I should be able to figure out what might be going on …

Yeah of course. I have it on github :slightly_smiling_face: Besides this is very interesting part from book:

Note that “numberOfRowsInSection” returns 0 for .notSearchedYet and no cells will ever be asked for. But because a switch must always be exhaustive, you also have to include a case for .notSearchedYet in “cellForRowAt”. Considering that it’s a bug when the code gets there you can use the built-in fatalError() function to help catch such mistakes.

UPD. So I repeat refactoring part and I found what the problem is. App now is working but when you change segment and searchbar has a text that you search and you press Enter this error will appear. In sourceCode folder this error has the same behavior.

I’m glad that you were able to sort out the issue :slight_smile: I didn’t have access to my computer till now and so could not look up what the relevant source code was. Plus, I only have the new version of the source code and so can’t be sure we are talking about the same thing :slight_smile:

If I understand you correctly, you are saying that if you have a search term in the search box and you switch to a different segment, this error appears, correct? I don’t see the same behaviour with the 6th edition source code. So just trying to identify if I have the correct issue so that I can correct this for later in the book if this is indeed an issue …

This was a bug with the 4th Edition source code indeed.

I forget exactly what caused it, but I believe it’s because Search.swift changed the state property in a different thread than the main thread.

Thanks, Matthijs :slight_smile: That’s one less thing to worry about, I guess …

Yeah, this bug is definitely with search.state. Now app working but sometimes crash. Erase simulator helps :slightly_smiling_face:

Here is another forum post on this issue, with the solution: Storesearch - Crashes if you search same thing twice in a row - #2 by hollance

Thanks. Now all working just fine :slight_smile:

This topic was automatically closed after 166 days. New replies are no longer allowed.