Kodeco Forums

Learn to Code iOS Apps with Swift Tutorial 2: Your First Project

In the second part of this five part series, you’ll put your new Swift skills to the test by making a simple number guessing game!

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1576-learn-to-code-ios-apps-with-swift-tutorial-2-your-first-project

Hey Ray - loving the tutorials, however…

Getting error messages on
let answer = randomIntBetween(0, 100) - 'Missing argument label ‘high:’ in call
let inputAsInt = userInput.toInt() - "toInt is unavailable:Use int() initializer

help please!

Thanks for the heads up! It’s all fixed!

One thing I have noticed in most of the tutorials on here is that you always have these supporting files and sometimes there are quite a few. Like this tutorial you just gloss over the arc4random thing which allows you to make this app and without it all the code is trash. I look at this and it does me no good. You don’t explain that supporting page at all and if you don’t understand that page you could never recreate this not even close.

That’s really helpful to know. Often times, we make assumptions when creating tutorials and sometimes forget about the target assumptions. I’ll make sure to keep your comments in mind as well as pass them off to the rest of the team.

Thanks so much!

Hi Ray,

Great tutorial. I am learning a lot.

One question:
why is this line necessary?

let inputAsInt = Int(userInput)

Isn’t this enough?

if let guess = Int(userInput)

Hi tamidkmo … Yeup, your approach would work great. In face, I would consider it the preferred approach. When we update the tutorial, I’ll make sure to incorporate your change.


its clear 'Missing argument label ‘high:’

let answer = randomIntBetween(0, **high:**100)

Great stuff!

One small note though. If you scroll down a little from the part “Implementing Rounds” you say: Your file should now look like this:
When you look at the script it’s already the entire end product. So I got confused that I maybe forgot some stuff.

Again great stuff!

Thanks! I’m glad you liked it!

Can you elaborate on why his approach is better? Is it simply removing verbose code? In the original code are we assigning “inputAsInt” to the value that the user inputs to the screen only to assign the optional “guess” the value of “inputAsInt”? In the “if let guess = Int(userInput)” statement you are just doing both in one statement correct? Thank you

Hey Ray,

Good stuff you have done here!

I’m facing this issue:
use of unresolved identifier ‘input’ in this line let userInput = input()

Please help.


hey Ray … i’m glad i found such an amazing tutorial…
i am on part 2 and i can’t access the helper file for method randominbetween() idk why…
if you or anyone can send to my email it fdalthaqeel@gmail.com
will be so helpful. cause i can’t continue without it.

I’m not sure what is going on … I’m able to download the file without any issues. You can download the completed project at the end of the tutorial. It’ll contain the helper file in the project.

Hey Brian,

In the “Implementing Rounds” section, the second block of code right after “Your file should now look like this:” has additions that you have not gone over yet. Such as adding var turn = 1, break, continue, turn = turn + 1

I believe that block of code should look like

import Foundation

let answer = randomIntBetween(0, high: 100)

while(true) {
print(“Enter a number between 1 and 100.”)

let userInput = input()
let inputAsInt = Int(userInput)
if let guess = inputAsInt {
if(guess > answer) {
} else if(guess < answer) {
} else {
print(“Correct! The answer was (answer).”)
} else {
print(“Invalid input! Please enter a number.”)

It’s not a huge deal, but I was a little confused that I was told something should look a way and it didn’t. I hope that’s helpful!

Thanks for the guide, it’s awesome!