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 Swift 2.0 Differentiating Between Objects Structs vs Classes

Koki Tanaka
Koki Tanaka
3,839 Points

anotherPerson.email is not the same value as somePerson.email

I use Xcode ver8.0.

I think I typed the codes exactly the same as the video but the value of anotherPerson.email is different from the one of somePerson. (somePerson.email is "tcook@...." and the other is ""pasan@...."" )

It would be great if you could tell me why it doesn't work properly.

My code is as below:

class Person{
    var fullName: String
    var email:String
    var age: Int

    init(name: String, email: String, age: Int){
        self.fullName = name
        self.email = email
        self.age = age
    }
}

var somePerson = Person(name: "Tim Cook", email: "tim.cook@apple.com", age: 54)
var anotherPerson = somePerson

somePerson.email = "tcook@apple.com"

somePerson.email
anotherUser.email

2 Answers

Hi its because you typed

anotherUser.email instead of anotherPerson.email

Koki Tanaka
Koki Tanaka
3,839 Points

Oh, my bad.... Thank you so much!!

Haha no worries I do that all the time its normal! if you need any help with anything let me know :)