I have a variable of type String in Swift, its content may be as follows:
var str:String = "45.7" //content is of float type
Or the contents may be:
var str:String = "45" //content is of int type
the content may also be of any other type having more numbers and/or decimals. How could I convert the String accordingly?
The variable is only one, there aren't two variables. And the value of the variable is not fixed, if it contains a decimal or not, it may contain a decimal point number or may not. The single variable may have the above possibilities of data stored.