
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert Boolean Variable to String in Swift
This tutorial will discuss how to write swift program to convert boolean type variable to string.
Swift support various datatypes and string and bool 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 Boolean represent bool values. Bool has only two values either true or false. And to create boolean type variable we use Bool keyword.
To convert bool type variable into string we uses String() function. This function convert any data type into string.
Syntax
Following is the syntax ?
String(variableName)
Below is a demonstration of the same ?
Input
Suppose our given input is ?
Bool = true
Output
The desired output would be ?
String = "true"
Example
The following program shows how to convert bool type variable to string.
import Foundation import Glibc // Bool type variable var mynum : Bool = false // Convert bool into string // Using String() function var myVar = String(mynum) print("String value:", myVar) print("Type of myVar variable:", type(of: myVar))
Output
String value: false Type of myVar variable: String