Working with Variables

#variables

Overview

Sample Codes

Example 1

It is a bit confusing ??? #learn

// var + var
class User {
    var name = "Sedat"
}

var user = User()
user.name = "Veysel"
user = User()
print(user.name)

// print: Sedat


////////////////////////////////////////////////////////////////////

// var + let
class User {
    var name = "Sedat"
}

let user = User()
user.name = "Veysel"
user = User()
print(user.name)

// print: !!! ERROR !!!


////////////////////////////////////////////////////////////////////

// let + var
class User {
    let name = "Sedat"
}

var user = User()
user.name = "Veysel"
user = User()
print(user.name)

// print: !!! ERROR !!!


////////////////////////////////////////////////////////////////////

// let + let
class User {
    let name = "Sedat"
}

let user = User()
user.name = "Veysel"
user = User()
print(user.name)

// print: !!! ERROR !!!

Sources

Videos

Articles / Documents

Last updated