Ghi chú / Chú thích (Comment) trong Swift
1. Single-line Comment
// This is a single-line comment
let name = "Swift" // Comment ở cuối dòng2. Multi-line Comment
/*
This is a
multi-line comment
*/
/*
* Can be formatted
* with asterisks
*/3. Nested Comments
Swift hỗ trợ nested comments:
/*
Outer comment
/* Nested comment */
Still in outer comment
*/4. Documentation Comments
4.1. Single-line documentation
/// Tính tổng hai số
func sum(a: Int, b: Int) -> Int {
return a + b
}4.2. Multi-line documentation
/**
Tính tổng hai số
- Parameters:
- a: Số thứ nhất
- b: Số thứ hai
- Returns: Tổng của a và b
*/
func sum(a: Int, b: Int) -> Int {
return a + b
}5. Markup trong Documentation
/**
# Heading
This function calculates the sum.
## Usage Example
let result = sum(a: 5, b: 3)
- Important: Parameters must be integers
- Note: Returns an Int value
- Warning: May overflow for large numbers
- Parameter a: First number
- Parameter b: Second number
- Returns: Sum of a and b
*/
func sum(a: Int, b: Int) -> Int {
return a + b
}6. Quick Help Markup
/**
Validates email address
- Author: Your Name
- Version: 1.0
- Since: iOS 15.0
*/
func validateEmail(_ email: String) -> Bool {
// Implementation
return true
}📝 Tóm tắt
//- Single-line comment/* */- Multi-line comment///- Single-line documentation/** */- Multi-line documentation- Hỗ trợ nested comments
- Markdown trong documentation
Last updated on
Swift