Whoops. I didn’t realize that the op reentered the conversation. I thought I was replying to cstock.
Update: @7stud @fahim I have been very busy with the holiday season, and that is why it has taken me a few days to get my code uploaded. I have done everything I can but the app still not is working properly. Yes, I am running Xcode 9.2. My Mac is a late 2011 and it is now running on macOS High Sierra. I have provided a link with my source code.
I’ve deleted xCode and reinstalled it. The last thing I can think to do is revert back to xCode 9.1 or 9.0. But as @fahim said, the version of xCode should not be the issue. Thank you for all your help and let me know if it is working on your machine.
One last thing. I found that the problem arises in chapter 6 on page 117 when a handler is added to the UIAlertAction. The source code does provided with the book in chapter 6 doesn’t even work for me. The slider will freeze after the first time “Hit Me” is pressed, and does not unfreeze unless the button is pressed again.
@cstock I just downloaded your source code and tried it under Xcode 9.2 at my end and it works fine for me. Just to be clear, these are the steps that I followed:
- Run the app.
- Move the slider to as close to the target as I can.
- Tapped the “Hit Me” button, waited for the alert and clicked “OK”.
- The slider moved back to the default position.
- I moved the slider again and was able to move it fine.
If you follow different steps (like not moving the slider first, let me know. But even trying it without moving the slider first worked fine for me.
The things I can think of for you to try would be:
- Try cleaning the project in Xcode and then running it.
- Try deleting the derived data folder (~/Library/Developer/Xcode/DerivedData) folder after closing Xcode.
- If you have a second machine that you can run Xcode on, try Xcode 9.2 on that with your project.
If none of the above work for you, then let me know and I’ll see if I can think of anything else that might help us figure out what is going on.
Your app works fine for me in Xcode 9.2 running on a Macbook Pro (early 2015) with High Sierra. I tried everything I could think of to get geekomancer’s app to freeze, but I had no luck, so I won’t bother retrying those things with your app.
Try cleaning the project in Xcode and then running it.
If you don’t know how to do that, in Xcode click on:
Product > Clean
And you can also click on Product, then hold down the option
key and Clean
will change to Clean Build Folder
, which used to be considered a “deep” clean. You can read about the difference here:
If I were you, I wouldn’t spend too much time worrying about getting Xcode 9.2 to work–just switch back to Xcode 9.1 and move on. By the time you finish the book, Apple will probably release Xcode 9.5 or Xcode 10 and whatever problems you were having with Xcode 9.2 will be irrelevant.
I have tried all of these things and still no luck. However, I did find one thing out. I tried running the app on my phone (iOS 11.2) and it works fine! This makes me wonder if it is a problem with the simulator. The simulator I am running is also on 11.2, but for some reason it doesn’t work. I’m not too worried about it, but it is very frustrating. @fahim are you running it on an iOS 11.2 simulator?
@7stud If I don’t figure out the issue soon, I will do this and move on. Thanks
And I was just wondering last night if you had tried on a device and was going to suggest that to you (and to @geekomancer) today OK, this is progress. So I think we can consider the simulator to be the root cause of the issue. And to answer your question, yes, I was running on an iOS 11.2 simulator - not on device.
So there are two things you can try here:
-
Select your simulator and reset it. You should be able to do that from the Simulator menu (not the Xcode menu). The option is Hardware - Erase All Content and Settings. Try running the app again on the same simulator after that.
-
Delete your simulator (the one you have been testing on) via the Window - Devices and Simulators option in the Xcode menu. Do note that the screen initially shows just the devices and you have to switch to the Simulator tab to see the list of simulators. If this screen still shows any iOS 11 or 11.1 simulators, be sure to delete them. If you only have 11.2 simulators, then delete the one you’ve been testing on and then add it back in again using the plus (+) button at the bottom of the list. Then try running the app on that simulator.
Personally, I’d try to get things running on Xcode 9.2 since it has fixes and updates that make Xcode a bit more stable/usable. But I do realize that if you are just starting out with Swift development, then getting through the book is more important than having a really stable version of Xcode So if none of the above works (and I can’t think of anything else to try) then you might want to go back to Xcode 9.1 and see how that works for you. However, you don’t need to delete Xcode 9.2 in order to do that. Simply rename the Xcode.app (for 9.2) to something like Xcode92.app and then download the XIP file for 9.1 from the Apple developer downloads and extract that into your Applications folder. You can have multiple versions of Xcode running side by side. That way, if you do run into the same issue with Xcode 9.1 (or if I can think of something else to try with Xcode 9.2) you don’t have to re-download 9.2 yet again
…and I forgot to ask before: What simulator have you been using? iPhone 8 plus? iPhone SE? Something else?
So there are two things you can try here
Wouldn’t deleting Xcode 9.2 and reinstalling accomplish the same thing?
I will do this and move on
You will discover that iOS versions and Xcode versions change so fast that while you are learning iOS programming it’s immaterial which version you use. As I mentioned before, I always try to use the exact version of the software that is used by whatever programming book I am reading.
Not necessarily the case if you are simply deleting the Xcode.app or replacing it when you say “Delete and reinstall”, which is what people normally do. The simulator data might not get re-created if you remove Xcode 9.2 and install it again since the I don’t know what happens during the first time run of Xcode. if the previous Xcode version is the same as the new version, I assume it does not do anything with the simulators, but I might be wrong.
Either way, explicitly doing so (instead of assuming it might happen) is probably best since if things start working after one step or the other, then we know where things went wrong. Plus, that answers the question for others who might have the same issue as to what to do instead of simply swapping Xcode installations.
I’m not arguing with you, I’m just trying to understand: when you delete Xcode.app, you are deleting a directory which contains the Simulator.app. It’s in the directory:
Xcode.app/Contents/Developer/Applications/Simulator.app
So, it seems to me that a new install of Xcode has to reinstall a fresh Simulator.app. I guess that doesn’t mean the Simulator.app isn’t corrupted from the get go and deleting the stuff you suggested may cause it to fix itself.
I didn’t think you were - I was just trying to explain the situation as I saw it The simulator app wasn’t what I was talking about when I said things remain behind. The simulator app is just part of the equation - the actual simulator contents (data, apps etc.) are not inside the Applications folder. They go under the ~/Library/Developer/Xcode folder under various folders - mostly iOS DeviceSupport if I recall correctly.
So, even when you delete the Xcode.app all that data remains behind. So my suspicion at this point is that it is an issue with the simulator data rather than the simulator app itself, if that makes sense?
Update: As an additional clarification (for anybody interested in the behind the scene workings of these things), the contents inside an app bundle (what goes inside the Xcode.app folder for example) are generally not modified at run time (though there are exceptions to this too).
So things which are created at runtime by an app (including the various simulators for Xcode) are actually stored under the user’s Library folder. So when I talk about simulators, I mean the actual simulator data (which defines how things are set up for that particular user and device - and here I mean the simulated device -) than the Simulator app which simply takes one of these configurations from the Library folder and presents it to you on Xcode as a simulated device.
Yep. Thanks for explaining. Now, I’m really curious if that will fix the problem that geekomancer and cstock are experiencing!
Hi all, thanks for the help, but this did not seem to work. @cstock did you get your project running properly?
A while ago I re-installed Xcode 9.1 and tested it, got the same issue.
Today, I tried @fahim and @7stud 's combined suggestions.
I first reset the Simulator device (Hardware → Erase…). Tested, no change.
Next, I cleaned both the project and the build folder (Command-Shift-K and Command-Option-Shift-K), quit Simulator, deleted the phone from Devices and Simulators — and there were no simulators running older iOS versions, so I only deleted the one I was using. Tested, no change.
I also tried running the project on my old (2010) MacBook Air, but it’s so weak that it couldn’t even run the Simulator.
Hmm … so that eliminates almost everything. Have you tried running the app on a device? It worked for @cstock that way. So I’m curious as to how it goes for you …
I am running iOS 11.2 and Xcode 9.2. I have experienced exactly the same problem when I try building the BullsEye app.
When I first run the app using iPhone SE simulator everything looks OK. Once I move the slider and tap “Hit Me” the alert show up. But when I tap the “Awesome” button to dismiss the alert, the view somehow seems to be frozen. “Round” stayed as “1”, “Score” stayed as “0” and the random number stayed the same and I cannot move the slider anymore.
Interestingly, both the “i” and “Star Over” buttons stay active. If I tap the “i” button the Score, Round and random number will update immediately and slider can be moved again.
I tested the same code using a real iPhone 6 Plus it works well without any problem. So the problem somehow seems to be with the simulator.
I’m really interest to know what’s the real cause here.
Where exactly do you have the “Awesome” button? That confused me a bit … But either way, the issue so far has been trying to figure out what is going on since the same code which gives issues on one machine runs fine on another.
But without being able to see the issue, I’m afraid I’m stumped. It feels like a simulator-specific issue but I don’t have any ideas as to a fix at the moment …
I’m just following the course (037 Closures). I’m following 100% Ray’s instruction so my source code is exactly the same as the course. BTW the “Awesome” button is on the alert box (which shows score for the current round).
The issue isn’t with the source since the code runs fine on an actual device. I’ve not been able to isolate what is causing the issue though. So unless somebody who has the issue figures it out or somebody can help me replicate it at my end, I’m afraid we’re at an impasse …
Do you have any earlier versions of Xcode installed? If not, can you install Xcode 9.1 and tell us if you have the same problem? Before you install an earlier version of Xcode rename your current Applications/Xcode.app to something else, like Xcode-9.2.app.
I’m following 100% Ray’s instruction so my source code is exactly the same as the course.
Have you tried downloading the example app and running it instead of your app?
@7stud I already tried it on Xcode 9.1. Same issue. I have already tried the example app. Same issue. As fahim mentioned above, it seems pretty clear that we are experiencing a Simulator issue. (That said, if im292957 has different results it could be interesting.)
Hi All,
I’m new to iOS development and am finding this tutorial to be amazing so far!
I just started and everything was going fine until I hit this exact same problem that the OP described. For clarity, the section where this bug first appears is Tutorial 1, Chapter 6, Section “The Alert”.
Once I add the handler closure, my slider freezes and none of the UIViews or UIControls update after the Alert box is closed. The UI elements update only after the “Hit Me” or “i” buttons are pressed. I tried all the deep cleaning steps described above and it still doesn’t work.
I tried a test where I commented out the line where we update the slider value in the “startNewRound” function and the slider no longer locks up after the Alert box is closed. However, the labels that are updated in the “updateLabels” function do not update until I touch the slider or the buttons.
This leads me to believe that perhaps the simulator is not refreshing the screen and returning control of the UI elements to the user that are updated.
Is there a function call that we can add to the end of the “startNewRound” function that will force the ViewController to update itself and all it’s children?
For context, I’m running Xcode 9.2 in MacOS High Sierra(10.13.2) on a MacBook Air(Mid 2011).
Thanks for all your input so far - hopefully we can find a solution!