BluGeni
BluGeni

Reputation: 3454

Set variable in class from another class

I have a class that looks like this:

class ContactsHolder {
    static let name = "joe"
}

and from another class I can call it like so:

println(ContactsHolder.name)

My question is how do I set that variable to something else?

I tried:

ContactsHolder.name = "bob" and get Cannot assign to the result of this expression

Am I going about this completely wrong or what do I need to do??

Upvotes: 0

Views: 252

Answers (1)

Eric Aya
Eric Aya

Reputation: 70094

With let you declare a constant that can't be modified.

You can use a variable instead:

class ContactsHolder {
    static var name = "joe"
}

ContactsHolder.name = "mike"

println(ContactsHolder.name) // prints "mike"

Upvotes: 3

Related Questions