Bỏ qua để đến nội dung

Ghi chú (Comment)

// This is a single-line comment
let name = "Swift" // Comment ở cuối dòng
/*
This is a
multi-line comment
*/
/*
* Can be formatted
* with asterisks
*/

Swift hỗ trợ nested comments:

/*
Outer comment
/* Nested comment */
Still in outer comment
*/
/// Tính tổng hai số
func sum(a: Int, b: Int) -> Int {
return a + b
}
/**
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
}
/**
# 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
}
/**
Validates email address
- Author: Your Name
- Version: 1.0
- Since: iOS 15.0
*/
func validateEmail(_ email: String) -> Bool {
// Implementation
return true
}

  • // - Single-line comment
  • /* */ - Multi-line comment
  • /// - Single-line documentation
  • /** */ - Multi-line documentation
  • Hỗ trợ nested comments
  • Markdown trong documentation