Swift Text Output
🖨️ Swift Text Output
This is mainly done using the print() function.
1. print() – Basic Text Output
The most commonly used function.
Output
✔ Automatically adds a new line at the end
2. Printing Variables
Output
3. String Interpolation
Used to insert variables inside a string.
Output
✔ Clean
✔ Safe
✔ Recommended way
4. Printing Multiple Values
Output
5. Custom Separator & Terminator
Custom Separator
Output
Custom Terminator (No New Line)
Output
6. Multi-line Text Output
Swift supports multi-line strings.
7. debugPrint() – Debug Output
Used mainly for debugging.
✔ 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:
✅ Correct way:
📌 Summary
| Method | Use |
|---|---|
print() |
Normal output |
| String Interpolation | Insert variables |
separator |
Customize separation |
terminator |
Control new line |
debugPrint() |
Debugging |
