The Swift standard library declares CommandLine as an enum.
/// Command-line arguments for the current process.
public enum CommandLine {
/// Access to the raw argc value from C.
public static var argc: Int32 { get }
/// Access to the raw argv value from C. Accessing the argument vector
/// through this pointer is unsafe.
public static var unsafeArgv: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?> { get }
/// Access to the swift arguments, also use lazy initialization of static
/// properties to safely initialize the swift arguments.
public static var arguments: [String]
}
The purpose of the API could very well be achieved by declaring CommandLine as a struct.
Any specific reason why it is declared as an enum instead of a struct?
Ok, based on some research, I found this:
The advantage of using a case-less enumeration is that it can't accidentally be instantiated and works as a pure namespace. (Ref: https://github.com/raywenderlich/swift-style-guide#constants)
I believe this could possibly be one of the reasons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With