I'm brand new to 'in depth' OOP and iOS development, so have been getting my hands dirty with it this week. I'm feeling more comfortable so decided to create a rock, paper, scissors game. I'm aware it's very simplistic and any critique on this VERY simple statement is welcome.
To compare the users and computer picks I created the compare picks function with a case statement embedded. The error i'm getting is that the function is not receiving anything to return, presumably because the return calls are all within the switch statement.
func comparePicks(var human: String, var computer: String) -> String {
switch human{
//Player Chooses Rock
case "Rock":
if computer == "Rock"{
return "Draw"}
else if computer == "Paper"{
return "Lose"}
else if computer == "Scissors"{
return "Win"}
//Player Chooses Scissors
case "Scissors":
if computer == "Scissors"{
return "Draw"}
else if computer == "Rock"{
return "Lose"}
else if computer == "Paper"{
return "Win"}
//Player Chooses Paper
case "Paper":
if computer == "Paper"{
return "Draw"}
else if computer == "Rock"{
return "Lose"}
else if computer == "Scissors"{
return "Win"}
default:
return "error"
}
// Error here - "Missing return in a function expected to return 'String'
}
Where do these get returned too, can a switch statement have returns, I haven't seen anything mentioned in the docs. How can I change this so the return is being given to the compare Picks function instead. TIA.