Post

How to Read Device Info in SwiftUI

Display system name, version, model, and device name in SwiftUI using UIDevice.

How to Read Device Info in SwiftUI

Expose basic device details directly in your UI. Use UIDevice.current with LabeledContent for a compact settings-style view.

SwiftUI Implementation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import SwiftUI
import UIKit

struct DeviceInfoView: View {
    private let device = UIDevice.current

    var body: some View {
        Form {
            LabeledContent("System Name", value: device.systemName)       // e.g., "iOS"
            LabeledContent("System Version", value: device.systemVersion) // e.g., "18.0"
            LabeledContent("Device Model", value: device.model)           // e.g., "iPhone"
            LabeledContent("Device Name", value: device.name)             // e.g., "iPhone 14 Pro Max"
        }
        .navigationTitle("Device Info")
    }
}

#Preview {
    NavigationStack { DeviceInfoView() }
}

UIDevice provides a simple, read-only snapshot of the current device. Values are localized strings and safe to read on the main thread.

Non-UI Access

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import UIKit

public struct DeviceInfo: Sendable {
    public let systemName: String
    public let systemVersion: String
    public let model: String
    public let name: String

    public static func current() -> Self {
        let d = UIDevice.current
        return .init(systemName: d.systemName,
                     systemVersion: d.systemVersion,
                     model: d.model,
                     name: d.name)
    }
}

// Example
let info = DeviceInfo.current()
print("\(info.systemName) \(info.systemVersion)\(info.model)\(info.name)")

Use the struct for logging or diagnostics. Avoid transmitting the user’s device name to servers unless necessary and consented.

☕ Support My Work

If you found this post helpful and want to support more content like this, you can buy me a coffee!

Your support helps me continue creating useful articles and tips for fellow developers. Thank you! 🙏

This post is licensed under CC BY 4.0 by the author.