# 将Unicode Int转换为字符串

``````let myInteger: Int = 97

// convert Int to a valid UnicodeScalar
guard let myUnicodeScalar = UnicodeScalar(myInteger) else {
return ""
}

// convert UnicodeScalar to String
let myString = String(myUnicodeScalar)

// results
print(myString) // a
``````

``````let myInteger: Int = 97
if let myUnicodeScalar = UnicodeScalar(myInteger) {
let myString = String(myUnicodeScalar)
}
``````

``````let x : Int = 45
let xNSNumber = x as NSNumber
let xString : String = xNSNumber.stringValue
``````

Swift 2：

``````var num1 = 4
var numString = "56"
var sum2 = String(num1) + numString
var sum3 = Int(numString)
``````

Swift 4

``````let x:Int = 45
let str:String = String(describing: x)
``````

Swift 4：

``````let str:String = String(x ?? 0)
``````

``````var numberA = Int("10")

Print(numberA) // It will print 10
``````

``````var numberA = 10
``````

``````print("numberA is \(numberA)") // It will print 10
``````

``````var strSomeNumber = String(numberA)
``````

``````var strSomeNumber = "\(numberA)"
``````

``````let x = 10.description
``````

swift 3.0中，这是我们如何将`Int`转换为`String``String`转换为`Int`

``````//convert Integer to String in Swift 3.0

let theIntegerValue :Int = 123  // this can be var also
let theStringValue :String = String(theIntegerValue)

//convert String to Integere in Swift 3.0

let stringValue : String = "123"
let integerValue : Int = Int(stringValue)!
``````

``````let a:String = String(stringInterpolationSegment: 15)
``````

``````let number: Int = 15
let _numberInStringFormate: String = String(number)
``````

//或者代替15的任何整数

`Int`转换为`String`

``````let x : Int = 42
var myString = String(x)
``````

``````let myString : String = "42"
let x: Int? = myString.toInt()

if (x != nil) {
// Successfully converted String to Int
}
``````

``````let x: Int? = Int(myString)
``````

`````` var a = Int()
var string1 = String("1")
a = string1.toInt()
``````

``````var a = Int()
a = 1
var string1 = String()
string1= "\(a)"
``````

``````let x : Int = 45
var stringValue = "\(x)"
print(stringValue)
``````

``````var x = 34
var s = String(x)
var ss = "\(x)"
var sss = toString(x)
var ssss = x.description
``````

``````let a =123456888
var str = String(a)
``````

``````var str = a as! String
``````