Skip to content

Instantly share code, notes, and snippets.

@samhenrigold
Last active October 1, 2026 16:00
Show Gist options
  • Select an option

  • Save samhenrigold/89b5909ecb2cf6b2f69e68f600ab78af to your computer and use it in GitHub Desktop.

Select an option

Save samhenrigold/89b5909ecb2cf6b2f69e68f600ab78af to your computer and use it in GitHub Desktop.
Look up Apple device metadata and system artwork from hardware model identifiers using Uniform Type Identifiers
// Created by Sam Henri Gold on 2026-10-01.
import Cocoa
import UniformTypeIdentifiers
public struct AppleDeviceType: Hashable, Sendable, CustomStringConvertible {
public let modelIdentifier: String
public let contentType: UTType
public init?(
_ modelIdentifier: String,
conformingTo supertype: UTType? = nil
) {
guard
!modelIdentifier.isEmpty,
let contentType = UTType(
tag: modelIdentifier,
tagClass: .appleDeviceModelCode,
conformingTo: supertype
),
contentType.isDeclared
else {
return nil
}
self.modelIdentifier = modelIdentifier
self.contentType = contentType
}
public var identifier: String {
contentType.identifier
}
public var localizedName: String? {
contentType.localizedDescription
}
public var modelCodes: [String] {
contentType.tags[.appleDeviceModelCode] ?? []
}
public var icon: NSImage {
NSWorkspace.shared.icon(for: contentType)
}
public var description: String {
localizedName ?? identifier
}
}
private extension UTTagClass {
static let appleDeviceModelCode = UTTagClass(rawValue: "com.apple.device-model-code")
}
@samhenrigold

Copy link
Copy Markdown
Author

Usage:

let device = AppleDeviceType("iPod2,1")!

print(device.identifier)
// com.apple.ipod-touch-2

print(device.localizedName ?? "Unknown")
// iPod touch

print(device.modelCodes)
// ["N72AP", "iPod2,1"]

let image = device.icon

Result of image:

CleanShot 2026-10-01 at 11 55 07 AM@2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment