The Example module demonstrates a comprehensive Swift package structure with various API patterns and implementations suitable for testing documentation generation tools.
This module showcases different Swift programming patterns including:
- Protocol-based design with
ExampleProtocol - Class implementations with private/internal members
- Struct configurations with validation and state management
- Enum types with both public and private cases
- Utility functions in a namespaced enum
- Access control patterns (public vs private)
| Type | Name |
|---|---|
| class | ExampleClass |
| struct | ExampleConfig |
| enum | ExampleUtilities |
| enum | OperationMode |
| protocol | ExampleProtocol |
/// A concrete implementation of ExampleProtocol
public class ExampleClass: ExampleProtocol {
/// The current operation mode
public var currentMode: OperationMode { get }
/// The name of the example instance
public let name: String
/// Doubles the input value
/// - Parameter value: The value to double
/// - Returns: The doubled value
public func calculate(_ value: Int) -> Int
/// A demonstration method that combines greeting and calculation
/// - Parameter value: A value to use in the calculation
/// - Returns: A tuple containing both greeting and calculation result
public func demonstrate(with value: Int) -> (greeting: String, result: Int)
/// Returns a greeting message including the instance name
public func greet() -> String
/// Initialize with a name
/// - Parameter name: The name for this instance
public init(name: String)
/// Change the operation mode
/// - Parameter mode: The new operation mode
public func setMode(_ mode: OperationMode)
}/// A simple struct that represents configuration options
public struct ExampleConfig: Sendable {
/// Default configuration
public static let `default`: ExampleConfig
/// Enable debug mode
public var debugEnabled: Bool
/// Maximum number of iterations
public var maxIterations: Int
/// Optional timeout interval
public var timeout: TimeInterval?
/// Initialize with custom configuration
public init(debugEnabled: Bool = false, maxIterations: Int = 10, timeout: TimeInterval? = nil)
/// Update configuration with new values
public mutating func update(debugEnabled: Bool? = nil, maxIterations: Int? = nil, timeout: TimeInterval? = nil)
/// Validate the current configuration
/// - Returns: True if configuration is valid
public func validate() -> Bool
}/// A namespace for utility functions
public enum ExampleUtilities {
/// Calculate the factorial of a number
/// - Parameter n: The number to calculate factorial for
/// - Returns: Factorial result
public static func factorial(_ n: Int) -> Int
/// Formats a number with thousands separator
/// - Parameter number: The number to format
/// - Returns: Formatted string representation
public static func formatNumber(_ number: Int) -> String
/// Validates if a string meets basic criteria
/// - Parameter input: The string to validate
/// - Returns: True if valid, false otherwise
public static func validate(_ input: String) -> Bool
}/// An enum representing different operation modes
public enum OperationMode {
/// Returns a description of the mode
public var description: String { get }
/// The performance multiplier for this mode
public var performanceMultiplier: Double { get }
/// Accurate operation mode with increased processing
public case accurate
/// Fast operation mode with reduced accuracy
public case fast
/// Legacy compatibility mode (not exposed publicly)
public case legacy
/// Standard operation mode
public case standard
/// Internal testing mode (not exposed publicly)
public case testing
/// Get the recommended timeout for this mode
/// - Parameter baseTimeout: The base timeout in seconds
/// - Returns: Adjusted timeout for this mode
public func recommendedTimeout(baseTimeout: TimeInterval) -> TimeInterval
/// Check if the mode supports high precision operations
/// - Returns: True if high precision is supported
public func supportsHighPrecision() -> Bool
}/// A simple example protocol that demonstrates basic functionality
public protocol ExampleProtocol {
/// Performs an example calculation
public func calculate(_ value: Int) -> Int
/// Returns a greeting message
public func greet() -> String
}