List of devices that can be previewed in Swift UI

Purpose

The Swift UI has the ability to preview how the screen under development will actually look.
At that time, you can specify the terminal that can be previewed, but by default there is only a way to specify it with rawValue, and there are problems such as not finding the terminal you want to preview & hotbed of typo, so list the terminals created.

environment

list

enum DeviceList: String {
    case iPhone_4s = "iPhone 4s"
    case iPhone_5 = "iPhone 5"
    case iPhone_5s = "iPhone 5s"
    case iPhone_6_Plus = "iPhone 6 Plus"
    case iPhone_6 = "iPhone 6"
    case iPhone_6s = "iPhone 6s"
    case iPhone_6s_Plus = "iPhone 6s Plus"
    case iPhone_SE_1st_generation = "iPhone SE (1st generation)"
    case iPhone_7 = "iPhone 7"
    case iPhone_7_Plus = "iPhone 7 Plus"
    case iPhone_8 = "iPhone 8"
    case iPhone_8_Plus = "iPhone 8 Plus"
    case iPhone_X = "iPhone X"
    case iPhone_Xs = "iPhone Xs"
    case iPhone_Xs_Max = "iPhone Xs Max"
    case iPhone_Xʀ = "iPhone Xʀ"
    case iPhone_11 = "iPhone 11"
    case iPhone_11_Pro = "iPhone 11 Pro"
    case iPhone_11_Pro_Max = "iPhone 11 Pro Max"
    case iPhone_SE_2nd_generation = "iPhone SE (2nd generation)"
    case iPod_touch_7th_generation = "iPod touch (7th generation)"
    case iPad_2 = "iPad 2"
    case iPad_Retina = "iPad Retina"
    case iPad_Air = "iPad Air"
    case iPad_mini_2 = "iPad mini 2"
    case iPad_mini_3 = "iPad mini 3"
    case iPad_mini_4 = "iPad mini 4"
    case iPad_Air_2 = "iPad Air 2"
    case iPad_Pro_9_7inch = "iPad Pro (9.7-inch)"
    case iPad_Pro_12_9inch_1st_generation = "iPad Pro (12.9-inch) (1st generation)"
    case iPad_5th_generation = "iPad (5th generation)"
    case iPad_Pro_12_9inch_2nd_generation = "iPad Pro (12.9-inch) (2nd generation)"
    case iPad_Pro_10_5inch = "iPad Pro (10.5-inch)"
    case iPad_6th_generation = "iPad (6th generation)"
    case iPad_7th_generation = "iPad (7th generation)"
    case iPad_Pro_11inch_1st_generation = "iPad Pro (11-inch) (1st generation)"
    case iPad_Pro_12_9inch_3rd_generation = "iPad Pro (12.9-inch) (3rd generation)"
    case iPad_Pro_11inch_2nd_generation = "iPad Pro (11-inch) (2nd generation)"
    case iPad_Pro_12_9inch_4th_generation = "iPad Pro (12.9-inch) (4th generation)"
    case iPad_mini_5th_generation = "iPad mini (5th generation)"
    case iPad_Air_3rd_generation = "iPad Air (3rd generation)"
    case iPad_8th_generation = "iPad (8th generation)"
    case iPad_Air_4th_generation = "iPad Air (4th generation)"
    case Apple_TV = "Apple TV"
    case Apple_TV_4K = "Apple TV 4K"
    case Apple_TV_4K_at_1080p = "Apple TV 4K (at 1080p)"
    case Apple_Watch__38mm = "Apple Watch - 38mm"
    case Apple_Watch__42mm = "Apple Watch - 42mm"
    case Apple_Watch_Series_2__38mm = "Apple Watch Series 2 - 38mm"
    case Apple_Watch_Series_2__42mm = "Apple Watch Series 2 - 42mm"
    case Apple_Watch_Series_3__38mm = "Apple Watch Series 3 - 38mm"
    case Apple_Watch_Series_3__42mm = "Apple Watch Series 3 - 42mm"
    case Apple_Watch_Series_4__40mm = "Apple Watch Series 4 - 40mm"
    case Apple_Watch_Series_4__44mm = "Apple Watch Series 4 - 44mm"
    case Apple_Watch_Series_5__40mm = "Apple Watch Series 5 - 40mm"
    case Apple_Watch_Series_5__44mm = "Apple Watch Series 5 - 44mm"
    case Apple_Watch_SE__40mm = "Apple Watch SE - 40mm"
    case Apple_Watch_SE__44mm = "Apple Watch SE - 44mm"
    case Apple_Watch_Series_6__40mm = "Apple Watch Series 6 - 40mm"
    case Apple_Watch_Series_6__44mm = "Apple Watch Series 6 - 44mm"
}

Information acquisition source

If you go to [Official Documents](https://developer.apple.com/documentation/swiftui/securefield/previewdevice(_ :)), you can get a list of devices that can be previewed with the following command. $ xcrun simctl list devicetypes

The above list was created by processing the acquired device list by the following method. It's unsightly because I'm a beginner with regular expressions, but ...

$ xcrun simctl list devicetypes | grep -v "Device Types" | sed -e "s/\((\)\(com\.apple\.CoreSimulator\.SimDeviceType\.*\)\([0-9a-zA-Z\-]*\)\()$\)//g"



```swift
import Foundation
var rawText = """ //Result of the above command
iPhone 4s
iPhone 5
iPhone 5s
iPhone 6 Plus
iPhone 6
iPhone 6s
iPhone 6s Plus
iPhone SE (1st generation)
iPhone 7
...
"""
    .components(separatedBy: "\n")
var body = "enum DeviceList: String {\n"
rawText.forEach {
    let rawDevice = $0
        .components(separatedBy: " ")
        .map { $0.replacingOccurrences(of: "-", with: "") }
        .map { $0.replacingOccurrences(of: "(", with: "") }
        .map { $0.replacingOccurrences(of: ")", with: "") }
        .map { $0.replacingOccurrences(of: ".", with: "_") }
        .joined(separator: "_")    
    body.append("    case \(rawDevice) = \"\($0)\"\n")
}
body.append("}")
print(body)

reference

Recommended Posts

List of devices that can be previewed in Swift UI
In Swift UI of iOS14, scrolling process of list can be controlled by code
Summary of ORM "uroboroSQL" that can be used in enterprise Java
SKStoreReviewController implementation memo in Swift UI of iOS14
[Spring Boot] List of validation rules that can be used in the property file for error messages
Basic functional interface that can be understood in 3 minutes
Write a class that can be ordered in Java
Convenient shortcut keys that can be used in Eclipse
Summary of css selectors that can be used with Nookogiri
Create a jar file that can be executed in Gradle
Photo library in Swift UI
Introduction to Rakefile that can be done in about 10 minutes
Java (super beginner edition) that can be understood in 180 seconds
A program that counts the number of words in a List
How to change BackgroundColor etc. of NavigationBar in Swift UI
How to make a key pair of ecdsa in a format that can be read by Java
[Swift] I tried using ColorPicker (the one that can easily select colors) added in iOS14 [Swift UI]
Reference memo / In-memory LDAP server that can be embedded in Java
SwiftUI View that can be used in combination with other frameworks
Summary of JDK that can be installed with Homebrew (as of November 2019)
Create Master Detail in Swift UI
Implementing side menus in Swift UI
List of members added in Java 9
List of types added in Java 9
[Java 8] Until converting standard input that can be used in coding tests into a list or array
[Swift] I investigated the variable expansion "\ ()" that realizes the mysterious function of Swift UI.
[Android Studio] Description that can be continuously input in SQLite Database [Java]
This and that of Swift corner Radius
Customize View with View Modifier in Swift UI
[GCD] Basics of parallel programming in Swift
[rails] List of actions defined in Controller
Find an approximation of cosx in Swift
Object-oriented that can be understood by fairies
Log out a CSV file that can be read in Excel using logback
Technology excerpt that can be used for creating EC sites in Java training
[Swift5] Problem that Cell cannot be tapped when TextView is placed in TableViewCell
How to fix a crash when deleting Realm data in Swift UI List