-2

I have created swift class object and simply print their properties value.

ViewController

Which gives me error, like :

Object class

What is wrong here, something is missing ?

And yes, I have already tried solution which found and also referred some links. But can't find solution.

  1. swift setter causing exc_bad_access
  2. Swift - Custom setter on property
  3. Override a setter in swift
Community
  • 1
  • 1
VRAwesome
  • 4,721
  • 5
  • 27
  • 52

1 Answers1

1

Your name setter creates an infinite recursion:

In the setter you are assigning again into the same variable, which again calls the setter, and so on.

Your code would work just with:

var name: String  // no need for setter or getter
var age: Int     // no need for setter or getter
Sulthan
  • 128,090
  • 22
  • 218
  • 270