Q:

error: instance member 'tomato' cannot be used on type 'hamburger'

1.what I code
class hamburger {
var tomato: String
var patty: String
var bread: String
var number: Int
init(_ tomato: String, _ patty: String, _ bread: String, _ number: Int) {
    self.tomato = tomato
    self.patty = patty
    self.bread = bread
    self.number = number
}
init() {
    self.tomato = "tomato"
    self.patty = "patty"
    self.bread = "bread"
    self.number = 10
}
}   
let sandwich = hamburger("texas" , "iii" , "iii" , 10)
print(hamburger.tomato)

2.error message
Playground execution failed:

error: dotinstall.playground:342:7: error: instance member 'tomato' 
cannot be used on type 'hamburger'
print(hamburger.tomato)
  ^~~~~~~~~ ~~~~~~

3.The sample I followed
enter code here// Class

class User {
let name: String // property
var score: Int
init(name: String, score: Int) {
init(_ name: String, _ score: Int) {
    self.name = name
    self.score = score
}
init() {
    self.name = "bob"
    self.score = 30
 }
}

//let tom = User(name: "tom", score: 23)
let tom = User("tom", 23)
print(tom.name)
print(tom.score)

let bob = User()
print(bob.name)
print(bob.score)

I have coded like 1 following 3, but I got a error message like 2.
what I did to solve
・anyway follow this sample to be like same
・studied a basic of class syntax, initializer, instance on website
・was looking for a mistypes
・I checked the order of property
I don't why it is not worked even if I just follow the sample code.
please give me tips on the solution.
thanks

A:

You're making a mistake regarding object oriented programming. With hamburger.tomato you try to access the property tomato of the Class Hamburger, not the Object, which is sandwich here. So the solution would be:
print(sandwich.tomato)

In the future, what you might want to do is take a look at styling your code better. Classes(Hamburger) are written starting with an uppercased letter, while the objects, or instances(sandwich), of the Classes are written starting with a lowercased letter.

