Packages and Modules
Namespace Types
A type can group related helpers so callers use a clear prefix.
Group helpers under a type
namespace_types.swift
enum GeometryKit {
static func rectangleArea(width: Int, height: Int) -> Int {
return width * height
}
}
let width =
let height = 3
let area = GeometryKit.rectangleArea(width: width, height: height)
let label = "area=\(area)"
print(label)
enum GeometryKit {
static func rectangleArea(width: Int, height: Int) -> Int {
return width * height
}
}
let width =
let height = 3
let area = GeometryKit.rectangleArea(width: width, height: height)
let label = "area=\(area)"
print(label)
enum GeometryKit {
static func rectangleArea(width: Int, height: Int) -> Int {
return width * height
}
}
let width =
let height = 3
let area = GeometryKit.rectangleArea(width: width, height: height)
let label = "area=\(area)"
print(label)
namespace
Swift modules are namespaces, and small programs can also group related static helpers under an enum or struct name.