-1

I am using this code to convert INT to STRING :

var xyz:Int = 10

var penalty:String = toString(xyz)

I get this error:

'ViewController.Type' does not have a member named 'xyz'

I've tried alternate ways to convert INT to String and still am getting this error.

Michael Rize
  • 107
  • 7
  • Also here: [How to initialize properties that depend on each other](http://stackoverflow.com/questions/25854300/how-to-initialize-properties-that-depend-on-each-other), or here: [Type does not have a member](http://stackoverflow.com/questions/25582853/type-does-not-have-a-member). – Martin R Feb 19 '15 at 12:10

2 Answers2

2

From the:

The Swift Programming Language

Stored properties store constant and variable values as part of an instance, whereas computed properties calculate (rather than store) a value.

So in your case xyz is stored variable while penalty is computed variable because its value is calculated from xyz variable and you are considering both as stored properties. If you want to make it work outside the view did load method declare penalty as follow

var penalty:String{
    
    return toString(xyz)
}
Community
  • 1
  • 1
Zell B.
  • 10,266
  • 3
  • 40
  • 49
1

put in your code in override func viewDidLoad() Method or wrap it into a method.

Dheeraj Singh
  • 5,143
  • 25
  • 33