Swift Comments

💬 Swift Comments (Complete & Easy Guide)
They are ignored by the Swift compiler and do not affect program output.
1. Single-Line Comment
Used for short explanations.
✔ Starts with //
2. Multi-Line Comment
Used for long descriptions.
✔ Starts with /*
✔ Ends with */
3. Nested Comments (Special Feature 🔥)
Swift allows comments inside comments (many languages don’t!).
✔ Very useful for debugging large blocks
4. Documentation Comments (Doc Comments)
Used to generate official documentation.
Single-line Doc Comment
Multi-line Doc Comment
✔ Appears in Xcode Quick Help (⌥ + Click)
5. Commenting Out Code (Debugging)
Temporarily disable code without deleting it.
6. Best Practices for Comments
✅ Explain why, not obvious what
✅ Keep comments short & clear
✅ Use doc comments for functions
❌ Don’t over-comment simple code
🧠 Summary Table
| Comment Type | Syntax | Use |
|---|---|---|
| Single-line | // | Short notes |
| Multi-line | /* */ | Long notes |
| Nested | /* /* */ */ | Advanced usage |
| Doc comment | /// or /** */ | Documentation |
