Skip to content

Commit f207504

Browse files
feature: Adds Unit initializer by name
1 parent aa85fc7 commit f207504

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Sources/Units/Unit/Unit.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ public struct Unit {
3737
}
3838
}
3939

40+
/// Retrieve a unit by name. This name is compared to the global registry and the relevant unit is initialized.
41+
/// Only defined units are returned - complex unit name equations are not supported.
42+
///
43+
/// - Parameter symbol: A string name of the unit to retrieve. This cannot be a complex equation of names.
44+
public init(fromName name: String) throws {
45+
let definedUnit = try Registry.instance.getUnit(byName: name)
46+
self.init(definedBy: definedUnit)
47+
}
48+
4049
/// Create a unit from the defined unit object.
4150
/// - Parameter definedBy: A defined unit to wrap
4251
internal init(definedBy: DefinedUnit) {

0 commit comments

Comments
 (0)