Apollo Apollo - 1 year ago 38
Swift Question

Reference structure within definition - Swift

struct Person {
var age: Int
var name: String
var siblings: Int

func sameAge(Person: p1, Person: p2) -> Boolean {
return (p1.age == p2.age)

How can I reference a structure that I'm defining within its own definition, like in the example above?

The error I see is

Definition conflicts with previous value


Parameter types should go after the colon:

func sameAge(p1: Person, _ p2 : Person) -> Boolean {
    return (p1.age == p2.age)