O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Comments

We should use comments as needed to explain how and why our code is written. We should use block comments before custom types and functions. We should use double slashes to comment our code in one line. Here is an example of how comments should be written:

/// 
/// This is a block comment that should be used 
/// to explain a class or function 
/// 
public class EmployeeClass { 
  // This is an inline comment with double slashes  
  var firstName = "" 
  var lastName = "" 
 
  /// 
  /// Use Block comments for functions 
  /// 
  /// parameter paramName:  use this tag for parameters 
  /// returns:    explain what is returned 
  /// throws:    Error thrown 
  /// 
  func getFullName() -> String {  
    return firstName + " " + lastName 
  } 
} 

When we are commenting methods, we should ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required