Swift Text Output

Swift Introduction

🖨️ Swift Text Output

In Swift text output means displaying text or values to the screen or console.

This is mainly done using the print() function.


 1. print() – Basic Text Output

The most commonly used function.

print("Hello, Swift!")

Output

Hello, Swift!

✔ Automatically adds a new line at the end


 2. Printing Variables


 

Output

Sanjit
25

 3. String Interpolation

Used to insert variables inside a string.


 

Output

Language: Swift, Version: 5.9

✔ Clean
✔ Safe
✔ Recommended way


 4. Printing Multiple Values


Output

Swift is awesome

 5. Custom Separator & Terminator

Custom Separator


Output

A-B-C

Custom Terminator (No New Line)


Output

Hello Swift

 6. Multi-line Text Output

Swift supports multi-line strings.



 7. debugPrint() – Debug Output

Used mainly for debugging.


✔ Shows detailed info

✔ Used in development, not production


 8. Printing Optional Values



 9. Output in Swift Playgrounds & Xcode

  • Swift Playgrounds → Output shown instantly

  • Xcode → Output appears in Console Panel


🧠 Common Mistakes

❌ Using + for strings:

print("Age is " + age) // Error

✅ Correct way:

print("Age is \(age)")

📌 Summary

Method Use
print() Normal output
String Interpolation Insert variables
separator Customize separation
terminator Control new line
debugPrint() Debugging

You may also like...