Marin
Marin

Reputation: 12910

Swift Viewcontroller.type does not have a member named

This is my code at the very top I have:

var newPurchase:Purchase = Purchase()

Then at the bottom I have :

class func updateLabels(label: UILabel, item: String)
{
    label.text = newPurchase.purchaseLemonsBalance  //  ViewController.type does not have a member named 'newPurchase'
}

Upvotes: 1

Views: 981

Answers (1)

Matthias Bauch
Matthias Bauch

Reputation: 90117

You can't access instance variables in class functions.

If you want to access instance variables you have to turn your class function into an instance function:

change

class func updateLabels(label: UILabel, item: String)

to

func updateLabels(label: UILabel, item: String)

Upvotes: 2

Related Questions