Tutorial 1 BullsEye - Slider freezes after first 'Hit Me' - Closure handler seems to be the cause

Hello, I just updated to Xcode 9.2, and the game tutorial seems to be broken now.

Here’s the issue: when I run the game, I can use the slider normally until I activate showAlert() by pressing “Hit Me”. After clicking “Ok”, the slider freezes and does not work. I can press “Hit Me” again, which advances the round, but can’t move the slider.

Tests tested:

If I remove handler: { action in self.startNewRound() }, and replace it with handler: nil, the slider issue goes away and the game works normally — except of course jumping to a new round before clicking “Ok”.

I have not yet added the info view, so the info button has no outlets or actions. However, if I press the info button, the game invokes startNewRound() and starts working normally again.

These clues seem to indicate that the handler is not actually closing the UIAlertAction when I press “Ok”, but only later when I do some other interaction with the UI.

Is this a bug in the new version Xcode (less likely)? Or did I miss something obvious (more likely)?

Thank you.

Edit: The issue seems to exist in the cheat code also. Should I Time Machine back to Xcode 9.1? Still not going to rule out that I may have missed something…

I just tested the final project in Xcode 9.2 and it works fine. So I don’t believe this is an Xcode 9.2 issue. The fact that the bundled project doesn’t work for you either is however a bit puzzling - unless of course, you meant something else when you said “cheat code” :slight_smile:

The easiest way to see what might be going on is for you to provide me with a copy of your project. I can try running it at my end to see if I see the same issue. If I do, I should be able to tell you what is wrong. You can upload the project somewhere (like DropBox) and post the link here and then I can take a look.

A couple of days ago, I upgraded from Xcode 9.1 to 9.2, and I just ran BullsEye in 9.2 and it works fine for me, i.e. the slider doesn’t freeze. While my code isn’t identical to the book’s code, the main parts are the same.

In any case, if you are clicking on a button which has not been connected but something executes, then I think your connections must be screwed up. I suggest you pull up the Connections Inspector and delete any connections that are frivolous and add any connections that are missing. You should be aware that if you change the name of an IBOutlet that you already connected, then you will create a new, unconnected IBOutlet, and the old connection to a now non-existent IBOutlet will still exist. Did you change the names of some of your IBOutlets?

I’m guessing you mean the sample code at the end of each chapter? How is anyone supposed to know which chapter you are referring to?

@fahim and @7stud thanks for your replies. Sorry about the unclarity re “cheat code”. Yes, I meant the reference source code, and I tried a few of them from around the point where I stopped — chapters 6 and 7 starter and final.

@7stud, to be more clear : any button (info, hit me, start over) seems to un-freeze the slider and move on to the next round (or start new game in the case of the start over button). That said, your point is well taken. I deleted all my @IBOutlet and @IBAction connections, and reconnected them. Still no good.

One other issue I did notice: All the buttons stay in the .highlighted position even after I release them. I’ve been looking through my code, must have a typo somewhere, but can’t seem to find it! :exploding_head:

I tried the chapter 6 final project in Xcode 9.2 - works fine. So issue might either be at your end or with your project but unfortunately, not able to replicate here.

So, if you can supply your project as I suggested before, I can see if I can replicate the issue with your code. But otherwise, I’m afraid that I’m not in a position to help.

Of course! And thank you.

I’m sorry, but I can’t replicate the issue you’re seeing with your code either. I do see some other issues with the layout (like not everything fitting correctly on the iPhone 8 simulator) but when I move the slider and tap “Hit Me”, the alert comes up and after I tap “OK”, I can move the slider again without any issues.

So it looks as if the issue might be local to your machine for some reason. The first thing to try might be to reboot your machine - if you have not rebooted since the issue started.

Alternatively, if you have a second machine where you can run Xcode, you might want to try running it on the second machine to verify that the issue is indeed specific to your development machine.

@fahim thanks for your help. Yes, layout-wise I’m following the basic tutorial, where they do the layout constraints later. For now it looks correct on SE :slight_smile:

This issue started when I updated Xcode to 9.2. There was a crash during the installation, but installed successfully after that. Yes I have rebooted since then. I’m going to try reverting to 9.1 via Time Machine (or deleting Xcode altogether), and then re-installing 9.2.

Anyway, I will continue troubleshooting on my own. I’m also currently updating Xcode on my laptop, to test it on there.

Will post my success and/or failure in a day or two.

Thanks again!

Boy, that’s frustrating.

I would delete Xcode 9.2 and reinstall and see if that cures the problem. I ran your Dropbox code in Xcode 9.2, and the slider works normally and so do the buttons.

By the way, if you want to keep old versions of Xcode around–I always do–then create a folder called XcodeX.X inside Applications and drag Xcode.app into that folder. Then download the new version of Xcode and it will appear as Xcode.app in the Applications folder. Create an empty folder named XcodeX.X for that version as well. You can switch Xcode versions by dragging Applications/Xcode.app into whichever Applications/XcodeX.X folder is empty, then drag Xcode.app out of one of the other Applications/XcodeX.X folders.

I am having the same exact problem. I updated to Xcode 9.2 and the slider freezes after the first time I press the Hit Me button. @geekomancer did you ever resolve the issue? The project was working fine in Xcode 9.1.

Are you logging the value of the slider inside sliderMoved()? Are you seeing any output in Xcode?

The problem I’m seeing is that any button I press stays in the .highlighted state. This causes the slider to freeze.

If I change this line: handler: { action in self.startNewRound() }
to: handler: nil
, the buttons (and slider) work as expected, but of course then the screen updates too soon.

The slider value logs as expected, but as stated it freezes after pressing the hit me button (or any button).

I have tried re-installing Xcode, deleting prefs, etc. I don’t know what else to do. I feel like I’ve wasted money on this course. It’s discouraging to have such a roadblock on the very first app, that seems to only be affecting some people.

It is not an issue with the course or with the code for the app since, as you’ll note from the previous conversation, I took your project and the code ran fine at my end without the issue under Xcode 9.2. My feeling would be that it is something to do with either the Xcode upgrade itself or something left over - like previous results of a compilation of the project.

The only other things I can think of to try would be to: a) try cleaning the project and rebuilding it, or, b) delete the derived data folder and try again. Re-installing Xcode does not clear your existing data unless you seek out all the places where Xcode data is saved. So that generally might not solve any issues unless it was an issue with the Xcode binary itself.

If neither of the above works for you, you can certainly upload a copy of your project too and provide a link and I can try that too. But if I can’t see the issue, I’m afraid that I’m not going to be in a position to help. But I can try.

lol. Apparently, you are not aware that Apple !#!#s developers on almost every upgrade of Xcode. Read the comments on the Xcode download page and see what Apple’s reputation is like among developers. Whenever you upgrade Xcode, it’s a risk.

Also, for almost any programming book in any language the code in the book only works for the version of the language that the book was written for. iOS Apprentice v6.0 was written for Xcode 9.0, so if I were you I would use that version for the entirety of the book. Having said that, I upgraded to Xcode 9.2 (and I also saved Xcode 9.1 just in case), and with no other changes my BullsEye app worked fine. So if Xcode 9.2 works on some hardware and not other hardware, whose fault do you think that is?

That’s slightly erroneous information, I’m afraid :slight_smile: While it is true that the sixth edition of the iOS Apprentice was written and tested on Xcode 9.0, there have been no changes to Xcode since then that prevents you from using the book with Xcode 9.1 or 9.2. So you do not need to go back to using Xcode 9.0 in order to use the book. While it is possible that the next Xcode release might bring breaking changes, you are fine up to Xcode 9.2.

In my opinion, the two people in this thread who are having problems with Xcode 9.2 are empirical evidence of the fallacy of that statement.

You are entitled to your opinion but given that the same code that doesn’t work for at least one of those people works fine when I compile and run it at my end on Xcode 9.2, I don’t think the issue is with Xcode 9.2. So suggesting that people have to use Xcode 9.0 to use the book is false advice. 'Nuff said.

geekomancer,

Post your code somewhere so that fahim and I can confirm whether it works for us in Xcode 9.2 or not.

He did post his code - scroll up. It’s @cstock who mentioned that he too is having issues. I have already tried @geekomancer’s code and it works fine at my end.

Thanks for the help and suggestions everybody. As a last resort I’m gonna try it on my old MacBook.

I have a very erratic and intensive work schedule, so will be on-and-off with this. Haven’t had any time to code for a couple weeks, but I’m still here. Will report any results.