Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Object-oriented programming in SWIFT Error

What am I doing wrong here??

struct Person {

let firstName: String
let lastName: String

func fullName (firstName: String, lastName: String) -> String {
  return "\(firstName) \(lastName)"
}

}

1 Answer

Are you writing this as part of the Overriding Methods code challenge? This is the provided code at the beginning of the challenge:

class Person {
  let firstName: String
  let lastName: String 

  init(firstName: String, lastName: String) {
    self.firstName = firstName
    self.lastName = lastName
  }

  func fullName() -> String {
    return "\(firstName) \(lastName)"
  }
}

It looks like you're creating a struct instead of a class and you're missing the initializer.

In this case, self.firstName = firstName is assigning values from the init method to local variables called firstName and lastName?

Louis Cornacchia, no, the values from the init method are not passed to local variables here. They are being set as the values of the properties for that object.