I've just started with Swift and am learning the basics. I've been playing around with Playgrounds and have come across an error whilst testing some code.
//creating a Struct for humans
struct Human {
var firstName: String? = nil
var surName: String? = nil
var age: Int? = nil
var height: Int? = nil
}
var personA = Human()
personA.firstName = "Jake"
personA.surName = "-"
personA.age = 26
personA.height = 185
print (personA)
if (personA.age == 30) {
print("You're 30 years old")
} else {
print("You're not 30")
}
var personB = Human()
personB.firstName = "Andy"
personB.surName = "-"
personB.age = 24
personB.height = 180
print (personB)
if (personA.height > personB.height) { //error here
print("Person A is taller, he is \(personA.height ?? 1)cms tall")
} else {
print("not true")
}
Could anybody explain why I'm receiving the error in simple terms?