Skip to content

Latest commit

 

History

History
22 lines (18 loc) · 1.07 KB

DefaultParameters.md

File metadata and controls

22 lines (18 loc) · 1.07 KB

Default Parameter Values

When do we use them?

Use default parameter values instead of creating convenience functions that pass common constant values to the original function

Key Considerations

  • The default value of a parameter should be the most common use case for the parameter
  • Always document the value of the default parameter

Example

/// Animate changes to one or more views using the specified duration and completion handler.
///
/// - Parameters:
///   - duration: The total duration of the animations, measured in seconds. If you specify a negative value or 0, the changes are made without animating them.
///   - animations: A block object containing the changes to commit to the views.
///   - completion: A block object to be executed when the animation sequence ends. Defaults to nil.
func animate(withDuration duration: TimeInterval, animations: @escaping () -> Void, completion: ((Bool) -> Void)? = nil)

Reference Docs