$ show devicekit/DeviceKit
DeviceKit is a pure-Swift library that provides a value-type replacement for Apple's UIDevice. It detects the exact device model (iPhone, iPad, iPod, Apple Watch, Apple TV) via hardware identifiers obtained from the system's uname() and maps them to an exhaustive enum with over 150 cases. Beyond identification, it exposes a rich set of computed properties such as screen diagonal, PPI, screen ratio, battery state (iOS/watchOS), cameras, Apple Pencil support, CPU/SoC, 5G support, USB-C connectivity, LiDAR sensor, Dynamic Island, and more. The library is architected as a single source file (Device.generated.swift) generated from a Python template (Device.swift.gyb) that encodes per-device metadata. It uses platform compilation guards (os(iOS), os(tvOS), os(watchOS)) to provide platform-specific APIs, and includes an indirect .simulator case to propagate properties through to simulated devices. DeviceKit has no external runtime dependencies and is distributed as a framework via CocoaPods, Carthage, and Swift Package Manager. Its primary entry point is `Device.current`, returning the running device as a value type, with static helpers like `Device.allPhones` and instance methods like `isOneOf(_:)` for group checks.
The LLM identified 2 files worth highlighting for reuse:
A standalone Python script that implements a lightweight template engine for generating boilerplate code. It parses a custom template syntax (%-lines, ${...} substitutions, %{...}% blocks) and executes Python code embedded in the template to produce text output. The engine supports nesting, dedent handling, and line directive injection for source mapping. This component is fully self-contained, requires only the Python standard library, and can be extracted to generate any type of source code (not just Swift) from data-driven templates. It demonstrates a clean separation of concerns: metadata defined in Python data structures drives the generation of exhaustive Swift enums and computed properties.
A GYB template that contains the authoritative database of Apple device specifications. It defines Python classes (Device) with fields for hardware identifiers, screen dimensions, PPI, camera types, CPU models, and boolean feature flags (e.g., hasTouchID, hasUSBCConnectivity). The template uses loops and conditionals to generate the entire Device.generated.swift file: the Device enum cases, identifier-to-case mapping, diagonal, screenRatio, ppi, cpu, and all static arrays (allPhones, allPads, allDevicesWithSensorHousing, etc.). This pattern is reusable for any project that needs to maintain a mapping from hardware identifiers to structured metadataβthe data layer is isolated in Python, making additions trivial without touching Swift logic. The template also demonstrates a clever use of bitmask integers to encode Apple Pencil support combinations.