instance member .... cannot be used on type

This code give err instance member theName cannot be used on type myClass
any suggestions?

//
//  ContentView.swift
//  myTest
//
//  Created by N.N on 2020-11-25.
//

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text(MyClass.theName as! String)
            .padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
class MyClass {
    var theName: String?
    init() {
        theName = "myName"
    }
}





You need to create an instance when you want to access an instance property (or an instance method) of a class.
Code Block
import SwiftUI
struct ContentView: View {
let myInstance = MyClass() //<- Create an instance of `MyClass`
var body: some View {
Text(myInstance.theName ?? "") //<- Access the instance property through the instance
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
class MyClass {
var theName: String?
init() {
theName = "myName"
}
}


Thankyou
I thought I tried that to but obvisly not correct
this works bu if I take away the comment before print I get
Cannot find type 'myInstance' in scope
that obvisly work in the Text statment
Why?

//
// ContentView.swift
// myTest
//
// Created by N.N on 2020-11-25.
//

import SwiftUI

struct ContentView: View {
  var myInstance = MyClass()
//  print(myInstance.theName)

  var body: some View {

    Text(myInstance.theName)
      .padding()
  }
}

struct ContentView_Previews: PreviewProvider {
  static var previews: some View {
    ContentView()
  }
}
class MyClass {
  var theName: String = "myName"
}
instance member .... cannot be used on type
 
 
Q