Swift Program to convert int type variable to string

This tutorial will discuss how to write swift program to convert int type variable to string.

Swift support various datatypes and string and integers are one of them. String is an ordered collection of characters. For example: “TutorialsPoint”, “Pinky”, etc. To create a string-type variable we use String keyword. Whereas Integers represent numeric values like 2, 3, 45, 6, etc. And to create integer-type variables we use the Int keyword.

To convert int type variable into string we uses String() function. This function convert any data type into string.


Following is the syntax −


Below is a demonstration of the same −


Suppose our given input is −

Num = 52324


The desired output would be −

String = “52324”


The following program shows how to convert int type variable to string.

import Foundation
import Glibc

// Integer type variable 
var mynum : Int = 23243

// Convert integer into string 
// Using String() function
var myVar = String(mynum)

print("String:", myVar)
print("Type of myVar variable:", type(of: myVar))


String: 23243
Type of myVar variable: String