func evaluateDate(nDate: Int!, rDate: Int!) -> Int{
if(nDate < rDate) {
return 1
}
if(nDate == rDate) {
return 2
}
if(nDate > rDate) {
return 3
}
}
Every time I get an error that says: "Missing return in a function expected to return 'Int'" However on the apple developer website they give an example of this doing
func sayHello(personName: String, alreadyGreeted: Bool) -> String {
if alreadyGreeted {
return sayHelloAgain(personName)
} else {
return sayHello(personName)
}
}
print(sayHello("Tim", alreadyGreeted: true))
// prints "Hello again, Tim!"
I don't understand what's going on because also in another place I try to change the value of a variable and it doesn't recognize the variable has changed outside the if-else block, however I don't ever remember this being an issue.
Aucun commentaire:
Enregistrer un commentaire