Skip to content

Commit e3db0ab

Browse files
rstacpooleclaude
andcommitted
Rename Quantity properties to lowerCamelCase; restore description
Addresses review feedback on the enum -> struct change: - Rename the static dimension properties to lowerCamelCase (.length, .mass, ...) per the Swift API Design Guidelines. The former PascalCase names are kept as @available(*, deprecated, renamed:) aliases so existing call sites keep compiling; they can be removed in a future major release. Internal call sites and tests now use the new names. - Add CustomStringConvertible returning rawValue, restoring the enum's behavior where "\(Quantity.length)" prints "Length" rather than the synthesized struct description. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 554bd5e commit e3db0ab

5 files changed

Lines changed: 270 additions & 226 deletions

File tree

Sources/Units/Quantity.swift

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
/// }
1010
/// ```
1111
///
12-
/// Use a unique `rawValue` for each distinct dimension — equality and hashing are based on it.
12+
/// Equality and hashing are based on `rawValue`, so each distinct dimension needs a unique
13+
/// raw string. Because the namespace is global across every module that links this package,
14+
/// two modules that independently pick the same raw value are treated as the *same* dimension
15+
/// and silently cancel against one another. Prefix custom raw values to avoid collisions —
16+
/// e.g. `"Acme.Money"` rather than `"Money"`.
1317
public struct Quantity: RawRepresentable, Hashable, Sendable {
1418
public let rawValue: String
1519

@@ -18,15 +22,49 @@ public struct Quantity: RawRepresentable, Hashable, Sendable {
1822
}
1923

2024
// Base ISQ quantities: https://en.wikipedia.org/wiki/International_System_of_Quantities#Base_quantities
21-
public static let Amount = Quantity(rawValue: "Amount")
22-
public static let Current = Quantity(rawValue: "Current")
23-
public static let Length = Quantity(rawValue: "Length")
24-
public static let Mass = Quantity(rawValue: "Mass")
25-
public static let Temperature = Quantity(rawValue: "Temperature")
26-
public static let Time = Quantity(rawValue: "Time")
27-
public static let LuminousIntensity = Quantity(rawValue: "LuminousIntensity")
25+
public static let amount = Quantity(rawValue: "Amount")
26+
public static let current = Quantity(rawValue: "Current")
27+
public static let length = Quantity(rawValue: "Length")
28+
public static let mass = Quantity(rawValue: "Mass")
29+
public static let temperature = Quantity(rawValue: "Temperature")
30+
public static let time = Quantity(rawValue: "Time")
31+
public static let luminousIntensity = Quantity(rawValue: "LuminousIntensity")
2832

2933
// Extended SI Units: https://en.wikipedia.org/wiki/Non-SI_units_mentioned_in_the_SI
30-
public static let Angle = Quantity(rawValue: "Angle")
31-
public static let Data = Quantity(rawValue: "Data")
34+
public static let angle = Quantity(rawValue: "Angle")
35+
public static let data = Quantity(rawValue: "Data")
36+
}
37+
38+
// MARK: - Deprecated PascalCase aliases
39+
40+
// The previous `enum Quantity` spelled its cases in PascalCase. These aliases keep existing
41+
// call sites compiling against the renamed lowerCamelCase properties (Swift API Design
42+
// Guidelines) and can be removed in a future major release.
43+
public extension Quantity {
44+
@available(*, deprecated, renamed: "amount")
45+
static let Amount = Quantity.amount
46+
@available(*, deprecated, renamed: "current")
47+
static let Current = Quantity.current
48+
@available(*, deprecated, renamed: "length")
49+
static let Length = Quantity.length
50+
@available(*, deprecated, renamed: "mass")
51+
static let Mass = Quantity.mass
52+
@available(*, deprecated, renamed: "temperature")
53+
static let Temperature = Quantity.temperature
54+
@available(*, deprecated, renamed: "time")
55+
static let Time = Quantity.time
56+
@available(*, deprecated, renamed: "luminousIntensity")
57+
static let LuminousIntensity = Quantity.luminousIntensity
58+
@available(*, deprecated, renamed: "angle")
59+
static let Angle = Quantity.angle
60+
@available(*, deprecated, renamed: "data")
61+
static let Data = Quantity.data
62+
}
63+
64+
// MARK: - CustomStringConvertible
65+
66+
extension Quantity: CustomStringConvertible {
67+
// Preserve the enum's behavior: interpolating a Quantity yields its raw value
68+
// (e.g. "Length"), not the synthesized struct description.
69+
public var description: String { rawValue }
3270
}

0 commit comments

Comments
 (0)