├── Documentation
└── Usage.md
├── Assets
└── Iphone12ColorSchemes.png
├── .swiftpm
└── xcode
│ ├── package.xcworkspace
│ └── xcuserdata
│ │ └── anton.paliakou.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
│ ├── xcuserdata
│ └── anton.paliakou.xcuserdatad
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
│ └── xcshareddata
│ └── xcschemes
│ └── PreviewDevice.xcscheme
├── .github
└── workflows
│ └── swift.yml
├── Tests
└── PreviewDeviceTests
│ ├── DeviceIpodTests.swift
│ ├── DeviceMacTests.swift
│ ├── DeviceAppleTVTests.swift
│ ├── DeviceWatchTests.swift
│ ├── DeviceIpadTests.swift
│ └── DeviceIphoneTests.swift
├── Sources
└── PreviewDevice
│ ├── CocoaPreivew
│ ├── NSViewPreview.swift
│ └── NSViewControllerPreview.swift
│ ├── UIKitPreview
│ ├── UIViewPreview.swift
│ └── UIViewControllerPreview.swift
│ ├── View+PreviewDevice.swift
│ └── Device.swift
├── PreviewDevice.podspec
├── LICENSE
├── Package.swift
└── README.md
/Documentation/Usage.md:
--------------------------------------------------------------------------------
1 | In Progress
2 |
--------------------------------------------------------------------------------
/Assets/Iphone12ColorSchemes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Toni77777/PreviewDevice/HEAD/Assets/Iphone12ColorSchemes.png
--------------------------------------------------------------------------------
/.swiftpm/xcode/package.xcworkspace/xcuserdata/anton.paliakou.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Toni77777/PreviewDevice/HEAD/.swiftpm/xcode/package.xcworkspace/xcuserdata/anton.paliakou.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/.github/workflows/swift.yml:
--------------------------------------------------------------------------------
1 | name: Swift
2 |
3 | on:
4 | push:
5 | branches: [ main ]
6 | pull_request:
7 | branches: [ main ]
8 |
9 | jobs:
10 | build:
11 |
12 | runs-on: macos-15
13 |
14 | steps:
15 | - uses: actions/checkout@v2
16 | - name: Build
17 | run: swift build -v
18 | - name: Run tests
19 | run: swift test -v
20 |
21 |
--------------------------------------------------------------------------------
/Tests/PreviewDeviceTests/DeviceIpodTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // DeviceIpodTests.swift
3 | //
4 | // Created by Anton Paliakou on 8/28/21.
5 | //
6 |
7 | import XCTest
8 | @testable import PreviewDevice
9 |
10 | final class DeviceIpodTests: XCTestCase {
11 |
12 | // MARK: - Ipod
13 |
14 | func testIpodHasCorretName() {
15 | let iphone: Device = .ipod7Gen
16 | XCTAssertEqual(iphone.rawValue, "iPod touch (7th generation)")
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Tests/PreviewDeviceTests/DeviceMacTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // DeviceMacTests.swift
3 | //
4 | // Created by Anton Paliakou on 8/28/21.
5 | //
6 |
7 | import XCTest
8 | @testable import PreviewDevice
9 |
10 | final class DeviceMacTests: XCTestCase {
11 |
12 | // MARK: - Mac
13 |
14 | func testMacHasCorretName() {
15 | let iphone: Device = .mac
16 | XCTAssertEqual(iphone.rawValue, "Mac")
17 | }
18 |
19 | // MARK: - MacC atalyst
20 |
21 | func testMacCatalystHasCorretName() {
22 | let iphone: Device = .macCatalyst
23 | XCTAssertEqual(iphone.rawValue, "Mac Catalyst")
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Sources/PreviewDevice/CocoaPreivew/NSViewPreview.swift:
--------------------------------------------------------------------------------
1 | //
2 | // NSViewPreview.swift
3 | //
4 | //
5 | // Created by Anton Paliakou on 10/16/21.
6 | //
7 |
8 | #if canImport(AppKit) && canImport(SwiftUI)
9 | import AppKit
10 | import SwiftUI
11 |
12 | public struct NSViewPreview: NSViewRepresentable {
13 |
14 | // MARK: - Properties
15 |
16 | private let view: NSView
17 |
18 | // MARK: - Init
19 |
20 | public init(view: NSView) {
21 | self.view = view
22 | }
23 |
24 | // MARK: - NSViewRepresentable
25 |
26 | public func makeNSView(context: Context) -> NSView {
27 | view
28 | }
29 |
30 | public func updateNSView(_ nsView: NSView, context: Context) {
31 | }
32 | }
33 | #endif
34 |
--------------------------------------------------------------------------------
/.swiftpm/xcode/xcuserdata/anton.paliakou.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | PreviewDevice.xcscheme_^#shared#^_
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | PreviewDevice
16 |
17 | primary
18 |
19 |
20 | PreviewDeviceTests
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Sources/PreviewDevice/UIKitPreview/UIViewPreview.swift:
--------------------------------------------------------------------------------
1 | //
2 | // UIViewPreview.swift
3 | //
4 | //
5 | // Created by Anton Paliakou on 10/15/21.
6 | //
7 |
8 | #if canImport(UIKit) && canImport(SwiftUI)
9 | import SwiftUI
10 | import UIKit
11 |
12 | public struct UIViewPreview: UIViewRepresentable {
13 |
14 | // MARK: - Properties
15 |
16 | private let view: UIView
17 |
18 | // MARK: - Init
19 |
20 | public init(view: UIView) {
21 | self.view = view
22 | }
23 |
24 | // MARK: - UIViewRepresentable
25 |
26 | public func makeUIView(context: Context) -> UIViewType {
27 | self.view
28 | }
29 |
30 | public func updateUIView(_ uiView: UIView, context: Context) {
31 | }
32 | }
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/PreviewDevice.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |spec|
2 | spec.name = "PreviewDevice"
3 | spec.version = "0.9.0"
4 | spec.summary = "PreviewDevice - library with elegant syntax for Preview Device in SwiftUI"
5 | spec.description = "PreviewDevice - is a sugar wrapper around the Apple Preview Device. SwiftUI"
6 | spec.homepage = "https://github.com/Toni77777/PreviewDevice"
7 | spec.license = "MIT"
8 | spec.author = { "Anton Paliakov" => "toxa95401@gmail.com" }
9 | spec.ios.deployment_target = "13.0"
10 | spec.osx.deployment_target = "10.15"
11 | spec.watchos.deployment_target = "6.0"
12 | spec.tvos.deployment_target = "13.0"
13 | spec.source = { :git => "https://github.com/Toni77777/PreviewDevice.git", :tag => "#{spec.version}" }
14 | spec.source_files = "Sources/PreviewDevice/*.swift"
15 | spec.swift_version = "4.2"
16 | end
--------------------------------------------------------------------------------
/Sources/PreviewDevice/UIKitPreview/UIViewControllerPreview.swift:
--------------------------------------------------------------------------------
1 | //
2 | // UIViewControllerPreview.swift
3 | //
4 | //
5 | // Created by Anton Paliakou on 10/15/21.
6 | //
7 |
8 | #if canImport(UIKit) && canImport(SwiftUI)
9 | import SwiftUI
10 | import UIKit
11 |
12 | public struct UIViewControllerPreview: UIViewControllerRepresentable {
13 |
14 | // MARK: - Properties
15 |
16 | private let viewController: UIViewController
17 |
18 | // MARK: - Init
19 |
20 | public init(viewController: UIViewController) {
21 | self.viewController = viewController
22 | }
23 |
24 | // MARK: - UIViewControllerRepresentable
25 |
26 | public func makeUIViewController(context: Context) -> UIViewController {
27 | viewController
28 | }
29 |
30 | public func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
31 | }
32 | }
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/Sources/PreviewDevice/CocoaPreivew/NSViewControllerPreview.swift:
--------------------------------------------------------------------------------
1 | //
2 | // NSViewControllerPreview.swift
3 | //
4 | //
5 | // Created by Anton Paliakou on 10/15/21.
6 | //
7 |
8 | #if canImport(AppKit) && canImport(SwiftUI)
9 | import AppKit
10 | import SwiftUI
11 |
12 | public struct NSViewControllerPreview: NSViewControllerRepresentable {
13 |
14 | // MARK: - Properties
15 |
16 | private let viewController: NSViewController
17 |
18 | // MARK: - Init
19 |
20 | public init(viewController: NSViewController) {
21 | self.viewController = viewController
22 | }
23 |
24 | // MARK: - NSViewControllerRepresentable
25 |
26 | public func makeNSViewController(context: Context) -> NSViewController {
27 | viewController
28 | }
29 |
30 | public func updateNSViewController(_ nsViewController: NSViewController, context: Context) {
31 | }
32 | }
33 | #endif
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Anton Paliakov
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | // swift-tools-version:5.3
2 | // The swift-tools-version declares the minimum version of Swift required to build this package.
3 |
4 | import PackageDescription
5 |
6 | let package = Package(
7 | name: "PreviewDevice",
8 | platforms: [.iOS(.v13), .tvOS(.v13), .watchOS(.v6), .macOS(.v10_15)],
9 | products: [
10 | // Products define the executables and libraries a package produces, and make them visible to other packages.
11 | .library(
12 | name: "PreviewDevice",
13 | targets: ["PreviewDevice"]),
14 | ],
15 | dependencies: [
16 | // Dependencies declare other packages that this package depends on.
17 | // .package(url: /* package url */, from: "1.0.0"),
18 | ],
19 | targets: [
20 | // Targets are the basic building blocks of a package. A target can define a module or a test suite.
21 | // Targets can depend on other targets in this package, and on products in packages this package depends on.
22 | .target(
23 | name: "PreviewDevice",
24 | dependencies: []),
25 | .testTarget(
26 | name: "PreviewDeviceTests",
27 | dependencies: ["PreviewDevice"]),
28 | ]
29 | )
30 |
--------------------------------------------------------------------------------
/Tests/PreviewDeviceTests/DeviceAppleTVTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // DeviceAppleTVTests.swift
3 | //
4 | // Created by Anton Paliakou on 8/28/21.
5 | //
6 |
7 | import XCTest
8 | @testable import PreviewDevice
9 |
10 | final class DeviceAppleTVTests: XCTestCase {
11 |
12 | // MARK: - Apple TV
13 |
14 | func testAppleTVHasCorretName() {
15 | let iphone: Device = .appleTV
16 | XCTAssertEqual(iphone.rawValue, "Apple TV")
17 | }
18 |
19 | // MARK: - Apple TV 4K
20 |
21 | func testAppleTV4KHasCorretName() {
22 | let iphone: Device = .appleTV4K
23 | XCTAssertEqual(iphone.rawValue, "Apple TV 4K")
24 | }
25 |
26 | func testAppleTV4K1080pHasCorretName() {
27 | let iphone: Device = .appleTV4K1080p
28 | XCTAssertEqual(iphone.rawValue, "Apple TV 4K (at 1080p)")
29 | }
30 |
31 | // MARK: - Apple TV 4K 2 Gen
32 |
33 | func testAppleTV4KGen2HasCorrectName() {
34 | let iphone: Device = .appleTV4K_2Gen
35 | XCTAssertEqual(iphone.rawValue, "Apple TV 4K (2nd generation)")
36 | }
37 |
38 | func testAppleTV4KGen21080pHasCorretName() {
39 | let iphone: Device = .appleTV4K1080p_2Gen
40 | XCTAssertEqual(iphone.rawValue, "Apple TV 4K (at 1080p) (2nd generation)")
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Sources/PreviewDevice/View+PreviewDevice.swift:
--------------------------------------------------------------------------------
1 | //
2 | // View+PreviewDevice.swift
3 | // PreviewDevice
4 | //
5 | // Created by Anton Paliakou on 8/26/21.
6 | //
7 |
8 | #if canImport(SwiftUI)
9 | import SwiftUI
10 |
11 | @available(iOS 13.0, OSX 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 6.0, *)
12 | public extension View {
13 |
14 | func previewDevice(device: Device) -> some View {
15 | previewDevice(PreviewDevice(rawValue: device.rawValue))
16 | .previewDisplayName(device.rawValue)
17 | }
18 |
19 | func previewDevices(devices: [Device]) -> some View {
20 | ForEach(devices, id: \.self) { device in
21 | previewDevice(device: device)
22 | }
23 | }
24 | }
25 |
26 | @available(iOS 13.0, macOS 11.0, macCatalyst 13.0, tvOS 13.0, watchOS 6.0, *)
27 | public extension View {
28 |
29 | func previewDevice(device: Device, colorScheme: ColorScheme) -> some View {
30 | previewDevice(device: device)
31 | .preferredColorScheme(colorScheme)
32 | }
33 |
34 | func previewDevice(device: Device, colorSchemes: [ColorScheme]) -> some View {
35 | ForEach(0.. some View {
46 | previewDevice(device: device)
47 | .previewInterfaceOrientation(orientation)
48 | }
49 |
50 | func previewDevice(device: Device, orientations: [InterfaceOrientation]) -> some View {
51 | ForEach(0.. some View {
58 | ForEach(0..
32 |
33 |
34 | ### Preview on device
35 |
36 | ```swift
37 | .previewDevice(device: .iphone12)
38 | ```
39 |
40 |
41 | ### Preview on devices
42 |
43 | ```swift
44 | .previewDevices(device: [.iphone8, .iphone11Pro .iphone12, .iphone12ProMax])
45 | ```
46 |
47 | ### Preview on device with color scheme (light, dark)
48 |
49 | ```swift
50 | .previewDevice(device: .iphone12, colorScheme: .light)
51 | ```
52 |
53 | ### Preview on device with ColorSchemes
54 |
55 | ```swift
56 | .previewDevice(device: .iphone12, colorScheme: [.light, .dark])
57 | ```
58 |
59 | ### Preview on device with orientation (InterfaceOrientation)
60 |
61 | ```swift
62 | .previewDevice(device: .iphone12, orientation: .portrait)
63 | ```
64 |
65 | ### Preview on device with orientations
66 |
67 | ```swift
68 | .previewDevice(device: .iphone12, orientations: [.portrait, .landscapeLeft, .landscapeRight])
69 | ```
70 |
71 | ### Preview on device with orientation and color schemes
72 |
73 | ```swift
74 | .previewDevice(device: .iphone12, orientation: .portrait, colorSchemes: [.light, .dark])
75 | ```
76 |
77 | ## Installation
78 |
79 | ### [CocoaPods](https://guides.cocoapods.org/using/using-cocoapods.html)
80 | Specify next line in Podfile:
81 |
82 | ```ruby
83 | pod PreviewDevice
84 | ```
85 |
86 | ### [Swift Package Manager](https://github.com/apple/swift-package-manager)
87 |
88 | Open Xcode, File -> Swift Packages -> Add Packages.. and paste library git url:
89 |
90 | ```
91 | https://github.com/Toni77777/PreviewDevice.git
92 | ```
93 |
94 | ## Articles
95 | [Meet PreviewDevice 0.7.0](https://dev.to/toni777772/meet-previewdevice-0-7-0-1dpg)
96 |
97 | [What's new in PreviewDevice 0.8.0](https://dev.to/toni777772/what-s-new-in-previewdevice-0-8-0-5dc0)
98 |
99 | ## License
100 | PreviewDevice is released under the MIT license.
101 |
--------------------------------------------------------------------------------
/.swiftpm/xcode/xcshareddata/xcschemes/PreviewDevice.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
38 |
39 |
45 |
46 |
48 |
54 |
55 |
56 |
57 |
58 |
68 |
69 |
75 |
76 |
82 |
83 |
84 |
85 |
87 |
88 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/Tests/PreviewDeviceTests/DeviceWatchTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // DeviceWatchTests.swift
3 | //
4 | // Created by Anton Paliakou on 8/28/21.
5 | //
6 |
7 | import XCTest
8 | @testable import PreviewDevice
9 |
10 | final class DeviceWatchTests: XCTestCase {
11 |
12 | // MARK: - Watch
13 |
14 | func testWatch_38mmHasCorretName() {
15 | let iphone: Device = .watch_38mm
16 | XCTAssertEqual(iphone.rawValue, "Apple Watch (38mm)")
17 | }
18 |
19 | func testWatch_42mmHasCorretName() {
20 | let iphone: Device = .watch_42mm
21 | XCTAssertEqual(iphone.rawValue, "Apple Watch (42mm)")
22 | }
23 |
24 | // MARK: - Watch Series 2 32mm, 42mm
25 |
26 | func testWatchSeries2_38mmHasCorretName() {
27 | let iphone: Device = .watchSeries2_38mm
28 | XCTAssertEqual(iphone.rawValue, "Apple Watch Series 2 (38mm)")
29 | }
30 |
31 | func testWatchSeries2_42mmHasCorretName() {
32 | let iphone: Device = .watchSeries2_42mm
33 | XCTAssertEqual(iphone.rawValue, "Apple Watch Series 2 (42mm)")
34 | }
35 |
36 | // MARK: - Watch Series 3 32mm, 42mm
37 |
38 | func testWatchSeries3_38mmHasCorretName() {
39 | let iphone: Device = .watchSeries3_38mm
40 | XCTAssertEqual(iphone.rawValue, "Apple Watch Series 3 (38mm)")
41 | }
42 |
43 | func testWatchSeries3_42mmHasCorretName() {
44 | let iphone: Device = .watchSeries3_42mm
45 | XCTAssertEqual(iphone.rawValue, "Apple Watch Series 3 (42mm)")
46 | }
47 |
48 | // MARK: - Watch Series 4 40mm, 44mm
49 |
50 | func testWatchSeries4_40mmHasCorretName() {
51 | let iphone: Device = .watchSeries4_40mm
52 | XCTAssertEqual(iphone.rawValue, "Apple Watch Series 4 (40mm)")
53 | }
54 |
55 | func testWatchSeries4_44mmHasCorretName() {
56 | let iphone: Device = .watchSeries4_44mm
57 | XCTAssertEqual(iphone.rawValue, "Apple Watch Series 4 (44mm)")
58 | }
59 |
60 | // MARK: - Watch Series 5 40mm, 44mm
61 |
62 | func testWatchSeries5_40mmHasCorretName() {
63 | let iphone: Device = .watchSeries5_40mm
64 | XCTAssertEqual(iphone.rawValue, "Apple Watch Series 5 (40mm)")
65 | }
66 |
67 | func testWatchSeries5_44mmHasCorretName() {
68 | let iphone: Device = .watchSeries5_44mm
69 | XCTAssertEqual(iphone.rawValue, "Apple Watch Series 5 (44mm)")
70 | }
71 |
72 | // MARK: - Watch Series 6 40mm, 44mm
73 |
74 | func testWatchSeries6_40mmHasCorretName() {
75 | let iphone: Device = .watchSeries6_40mm
76 | XCTAssertEqual(iphone.rawValue, "Apple Watch Series 6 (40mm)")
77 | }
78 |
79 | func testWatchSeries6_44mmHasCorretName() {
80 | let iphone: Device = .watchSeries6_44mm
81 | XCTAssertEqual(iphone.rawValue, "Apple Watch Series 6 (44mm)")
82 | }
83 |
84 | // MARK: - Watch Series 7 41mm, 45mm
85 |
86 | func testWatchSeries7_41mmHasCorretName() {
87 | let iphone: Device = .watchSeries7_41mm
88 | XCTAssertEqual(iphone.rawValue, "Apple Watch Series 7 (41mm)")
89 | }
90 |
91 | func testWatchSeries7_45mmHasCorretName() {
92 | let iphone: Device = .watchSeries7_45mm
93 | XCTAssertEqual(iphone.rawValue, "Apple Watch Series 7 (45mm)")
94 | }
95 |
96 | // MARK: - Watch Series 8 41mm, 45mm
97 |
98 | func testWatchSeries8_41mmHasCorrectName() {
99 | let watch: Device = .watchSeries8_41mm
100 | XCTAssertEqual(watch.rawValue, "Apple Watch Series 8 (41mm)")
101 | }
102 |
103 | func testWatchSeries8_45mmHasCorrectName() {
104 | let watch: Device = .watchSeries8_45mm
105 | XCTAssertEqual(watch.rawValue, "Apple Watch Series 8 (45mm)")
106 | }
107 |
108 | // MARK: - Watch SE 40mm, 44mm
109 |
110 | func testWatchSE_40mmHasCorretName() {
111 | let iphone: Device = .watchSE_40mm
112 | XCTAssertEqual(iphone.rawValue, "Apple Watch SE (40mm)")
113 | }
114 |
115 | func testWatchSE_44mmmmHasCorretName() {
116 | let iphone: Device = .watchSE_44mm
117 | XCTAssertEqual(iphone.rawValue, "Apple Watch SE (44mm)")
118 | }
119 |
120 | // MARK: - Watch SE 2 Gen 40mm, 44mm
121 |
122 | func testWatchSE_2Gen_40mmHasCorrectName() {
123 | let watch: Device = .watchSE_2Gen_40mm
124 | XCTAssertEqual(watch.rawValue, "Apple Watch SE (40mm) (2nd generation)")
125 | }
126 |
127 | func testWatchSE_2Gen_44mmHasCorrectName() {
128 | let watch: Device = .watchSE_2Gen_44mm
129 | XCTAssertEqual(watch.rawValue, "Apple Watch SE (44mm) (2nd generation)")
130 | }
131 |
132 | // MARK: - Watch Ultra 49mm
133 |
134 | func testWatchUltra_49mmHasCorrectName() {
135 | let watch: Device = .watchUltra_49mm
136 | XCTAssertEqual(watch.rawValue, "Apple Watch Ultra (49mm)")
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/Sources/PreviewDevice/Device.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Device.swift
3 | // PreviewDevice
4 | //
5 | //
6 | // Created by Anton Paliakou on 8/26/21.
7 | //
8 |
9 | import Foundation
10 |
11 | public enum Device: String {
12 |
13 | // MARK: - iPhone
14 |
15 | case iphone6Plus = "iPhone 6 Plus"
16 | case iphone6 = "iPhone 6"
17 | case iphone6s = "iPhone 6s"
18 | case iphone6sPlus = "iPhone 6s Plus"
19 | case iphoneSE_1Gen = "iPhone SE (1st generation)"
20 | case iphone7 = "iPhone 7"
21 | case iphone7Plus = "iPhone 7 Plus"
22 | case iphone8 = "iPhone 8"
23 | case iphone8Plus = "iPhone 8 Plus"
24 | case iphoneX = "iPhone X"
25 | case iphoneXs = "iPhone Xs"
26 | case iphoneXsMax = "iPhone Xs Max"
27 | case iphoneXr = "iPhone Xʀ"
28 | case iphone11 = "iPhone 11"
29 | case iphone11Pro = "iPhone 11 Pro"
30 | case iphone11ProMax = "iPhone 11 Pro Max"
31 | case iphoneSE_2Gen = "iPhone SE (2nd generation)"
32 | case iphone12Mini = "iPhone 12 mini"
33 | case iphone12 = "iPhone 12"
34 | case iphone12Pro = "iPhone 12 Pro"
35 | case iphone12ProMax = "iPhone 12 Pro Max"
36 | case iphone13Pro = "iPhone 13 Pro"
37 | case iphone13ProMax = "iPhone 13 Pro Max"
38 | case iphone13Mini = "iPhone 13 mini"
39 | case iphone13 = "iPhone 13"
40 | case iphoneSE_3Gen = "iPhone SE (3rd generation)"
41 | case iphone14 = "iPhone 14"
42 | case iphone14Plus = "iPhone 14 Plus"
43 | case iphone14Pro = "iPhone 14 Pro"
44 | case iphone14ProMax = "iPhone 14 Pro Max"
45 | case iphone15 = "iPhone 15"
46 | case iphone15Plus = "iPhone 15 Plus"
47 | case iphone15Pro = "iPhone 15 Pro"
48 | case iphone15ProMax = "iPhone 15 Pro Max"
49 | case iphone16 = "iPhone 16"
50 | case iphone16Plus = "iPhone 16 Plus"
51 | case iphone16Pro = "iPhone 16 Pro"
52 | case iphone16ProMax = "iPhone 16 Pro Max"
53 |
54 | // MARK: - iPad
55 |
56 | case ipad2 = "iPad 2"
57 | case ipadRetina = "iPad Retina"
58 | case ipadAir = "iPad Air"
59 | case ipadMini2 = "iPad mini 2"
60 | case ipadMini3 = "iPad mini 3"
61 | case ipadMini4 = "iPad mini 4"
62 | case ipadMini5 = "iPad mini (5th generation)"
63 | case ipadMini6 = "iPad mini (6th generation)"
64 | case ipadAir2 = "iPad Air 2"
65 | case ipadPro9_7inch = "iPad Pro (9.7-inch)"
66 | case ipadPro12_9inch = "iPad Pro (12.9-inch)"
67 | case ipad_5Gen = "iPad (5th generation)"
68 | case ipadPro12_9inch_2Gen = "iPad Pro (12.9-inch) (2nd generation)"
69 | case ipadPro10_5inch = "iPad Pro (10.5-inch)"
70 | case ipad_6Gen = "iPad (6th generation)"
71 | case ipad_7Gen = "iPad (7th generation)"
72 | case ipad_8Gen = "iPad (8th generation)"
73 | case ipad_9Gen = "iPad (9th generation)"
74 | case ipadPro11inch_1Gen = "iPad Pro (11-inch) (1st generation)"
75 | case ipadPro12_9inch_3Gen = "iPad Pro (12.9-inch) (3rd generation)"
76 | case ipadPro11inch_2Gen = "iPad Pro (11-inch) (2nd generation)"
77 | case ipadPro12_9inch_4Gen = "iPad Pro (12.9-inch) (4th generation)"
78 | case ipadAir_3Gen = "iPad Air (3rd generation)"
79 | case ipadAir_4Gen = "iPad Air (4th generation)"
80 | case ipadPro11inch_3Gen = "iPad Pro (11-inch) (3rd generation)"
81 | case ipadPro12_9inch_5Gen = "iPad Pro (12.9-inch) (5th generation)"
82 | case ipadAir_5Gen = "iPad Air (5th generation)"
83 |
84 |
85 | // MARK: - iPod
86 |
87 | case ipod7Gen = "iPod touch (7th generation)"
88 |
89 | // MARK: - Mac
90 |
91 | case mac = "Mac"
92 | case macCatalyst = "Mac Catalyst"
93 |
94 | // MARK: - Apple TV
95 |
96 | case appleTV = "Apple TV"
97 | case appleTV4K = "Apple TV 4K"
98 | case appleTV4K1080p = "Apple TV 4K (at 1080p)"
99 | case appleTV4K_2Gen = "Apple TV 4K (2nd generation)"
100 | case appleTV4K1080p_2Gen = "Apple TV 4K (at 1080p) (2nd generation)"
101 |
102 | // MARK: - Apple Watch
103 |
104 | case watch_38mm = "Apple Watch (38mm)"
105 | case watch_42mm = "Apple Watch (42mm)"
106 | case watchSeries2_38mm = "Apple Watch Series 2 (38mm)"
107 | case watchSeries2_42mm = "Apple Watch Series 2 (42mm)"
108 | case watchSeries3_38mm = "Apple Watch Series 3 (38mm)"
109 | case watchSeries3_42mm = "Apple Watch Series 3 (42mm)"
110 | case watchSeries4_40mm = "Apple Watch Series 4 (40mm)"
111 | case watchSeries4_44mm = "Apple Watch Series 4 (44mm)"
112 | case watchSeries5_40mm = "Apple Watch Series 5 (40mm)"
113 | case watchSeries5_44mm = "Apple Watch Series 5 (44mm)"
114 | case watchSE_40mm = "Apple Watch SE (40mm)"
115 | case watchSE_44mm = "Apple Watch SE (44mm)"
116 | case watchSeries6_40mm = "Apple Watch Series 6 (40mm)"
117 | case watchSeries6_44mm = "Apple Watch Series 6 (44mm)"
118 | case watchSeries7_41mm = "Apple Watch Series 7 (41mm)"
119 | case watchSeries7_45mm = "Apple Watch Series 7 (45mm)"
120 | case watchSE_2Gen_40mm = "Apple Watch SE (40mm) (2nd generation)"
121 | case watchSE_2Gen_44mm = "Apple Watch SE (44mm) (2nd generation)"
122 | case watchSeries8_41mm = "Apple Watch Series 8 (41mm)"
123 | case watchSeries8_45mm = "Apple Watch Series 8 (45mm)"
124 | case watchUltra_49mm = "Apple Watch Ultra (49mm)"
125 | }
126 |
--------------------------------------------------------------------------------
/Tests/PreviewDeviceTests/DeviceIpadTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // DeviceIpadTests.swift
3 | //
4 | // Created by Anton Paliakou on 8/28/21.
5 | //
6 |
7 | import XCTest
8 | @testable import PreviewDevice
9 |
10 | final class DeviceIpadTests: XCTestCase {
11 |
12 | func testIpad2HasCorretName() {
13 | let iphone: Device = .ipad2
14 | XCTAssertEqual(iphone.rawValue, "iPad 2")
15 | }
16 |
17 | func testIpadRetinaHasCorretName() {
18 | let iphone: Device = .ipadRetina
19 | XCTAssertEqual(iphone.rawValue, "iPad Retina")
20 | }
21 |
22 | // MARK: - Air, Air 2, Air 3, Air 4
23 |
24 | func testIpadAirHasCorretName() {
25 | let iphone: Device = .ipadAir
26 | XCTAssertEqual(iphone.rawValue, "iPad Air")
27 | }
28 |
29 | func testIpadAir2HasCorretName() {
30 | let iphone: Device = .ipadAir2
31 | XCTAssertEqual(iphone.rawValue, "iPad Air 2")
32 | }
33 |
34 | func testIpadAir_3GenHasCorretName() {
35 | let iphone: Device = .ipadAir_3Gen
36 | XCTAssertEqual(iphone.rawValue, "iPad Air (3rd generation)")
37 | }
38 |
39 | func testIpadAir_4GenHasCorretName() {
40 | let iphone: Device = .ipadAir_4Gen
41 | XCTAssertEqual(iphone.rawValue, "iPad Air (4th generation)")
42 | }
43 |
44 | func testIpadAir_5GenHasCorretName() {
45 | let ipad: Device = .ipadAir_5Gen
46 | XCTAssertEqual(ipad.rawValue, "iPad Air (5th generation)")
47 | }
48 |
49 | // MARK: - Ipad mini 2, mini 3, mini 4, mini 5
50 |
51 | func testIpadMini2HasCorretName() {
52 | let iphone: Device = .ipadMini2
53 | XCTAssertEqual(iphone.rawValue, "iPad mini 2")
54 | }
55 |
56 | func testIpadMini3HasCorretName() {
57 | let iphone: Device = .ipadMini3
58 | XCTAssertEqual(iphone.rawValue, "iPad mini 3")
59 | }
60 |
61 | func testIpadMini4HasCorretName() {
62 | let iphone: Device = .ipadMini4
63 | XCTAssertEqual(iphone.rawValue, "iPad mini 4")
64 | }
65 |
66 | func testIpadMini5GHasCorretName() {
67 | let iphone: Device = .ipadMini5
68 | XCTAssertEqual(iphone.rawValue, "iPad mini (5th generation)")
69 | }
70 |
71 | func testIpadMini6GHasCorretName() {
72 | let iphone: Device = .ipadMini6
73 | XCTAssertEqual(iphone.rawValue, "iPad mini (6th generation)")
74 | }
75 |
76 | // MARK: - Ipad 5 Gen, 6 Gen, 7 Gen, 8 Gen
77 |
78 | func testIpad_5GenHasCorretName() {
79 | let iphone: Device = .ipad_5Gen
80 | XCTAssertEqual(iphone.rawValue, "iPad (5th generation)")
81 | }
82 |
83 | func testIpad_6GenHasCorretName() {
84 | let iphone: Device = .ipad_6Gen
85 | XCTAssertEqual(iphone.rawValue, "iPad (6th generation)")
86 | }
87 |
88 | func testIpad_7GenHasCorretName() {
89 | let iphone: Device = .ipad_7Gen
90 | XCTAssertEqual(iphone.rawValue, "iPad (7th generation)")
91 | }
92 |
93 | func testIpad_8GenHasCorretName() {
94 | let iphone: Device = .ipad_8Gen
95 | XCTAssertEqual(iphone.rawValue, "iPad (8th generation)")
96 | }
97 |
98 | func testIpad_9GenHasCorretName() {
99 | let iphone: Device = .ipad_9Gen
100 | XCTAssertEqual(iphone.rawValue, "iPad (9th generation)")
101 | }
102 |
103 | // MARK: - Ipad Pro
104 |
105 | func testIpadPro9_7inchHasCorretName() {
106 | let iphone: Device = .ipadPro9_7inch
107 | XCTAssertEqual(iphone.rawValue, "iPad Pro (9.7-inch)")
108 | }
109 |
110 | func testIpadPro12_9inchHasCorretName() {
111 | let iphone: Device = .ipadPro12_9inch
112 | XCTAssertEqual(iphone.rawValue, "iPad Pro (12.9-inch)")
113 | }
114 |
115 | func testIpadPro12_9inch_2GenHasCorretName() {
116 | let iphone: Device = .ipadPro12_9inch_2Gen
117 | XCTAssertEqual(iphone.rawValue, "iPad Pro (12.9-inch) (2nd generation)")
118 | }
119 |
120 | func testIpadPro10_5inchHasCorretName() {
121 | let iphone: Device = .ipadPro10_5inch
122 | XCTAssertEqual(iphone.rawValue, "iPad Pro (10.5-inch)")
123 | }
124 |
125 | func testIpadPro11inch_1GenHasCorretName() {
126 | let iphone: Device = .ipadPro11inch_1Gen
127 | XCTAssertEqual(iphone.rawValue, "iPad Pro (11-inch) (1st generation)")
128 | }
129 |
130 | func testIpadPro12_9inch_3GenHasCorretName() {
131 | let iphone: Device = .ipadPro12_9inch_3Gen
132 | XCTAssertEqual(iphone.rawValue, "iPad Pro (12.9-inch) (3rd generation)")
133 | }
134 |
135 | func testIpadPro11inch_2GenHasCorretName() {
136 | let iphone: Device = .ipadPro11inch_2Gen
137 | XCTAssertEqual(iphone.rawValue, "iPad Pro (11-inch) (2nd generation)")
138 | }
139 |
140 | func testIpadPro11inch_3GenHasCorretName() {
141 | let iphone: Device = .ipadPro11inch_3Gen
142 | XCTAssertEqual(iphone.rawValue, "iPad Pro (11-inch) (3rd generation)")
143 | }
144 |
145 | func testIpadPro12_9inch_4GenHasCorretName() {
146 | let iphone: Device = .ipadPro12_9inch_4Gen
147 | XCTAssertEqual(iphone.rawValue, "iPad Pro (12.9-inch) (4th generation)")
148 | }
149 |
150 | func testIpadPro12_9inch_5GenHasCorretName() {
151 | let ipad: Device = .ipadPro12_9inch_5Gen
152 | XCTAssertEqual(ipad.rawValue, "iPad Pro (12.9-inch) (5th generation)")
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/Tests/PreviewDeviceTests/DeviceIphoneTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // DeviceIphoneTests.swift
3 | //
4 | // Created by Anton Paliakou on 8/28/21.
5 | //
6 |
7 | import XCTest
8 | @testable import PreviewDevice
9 |
10 | final class DeviceIphoneTests: XCTestCase {
11 |
12 | // MARK: - Iphone 6, 6 Plus
13 |
14 | func testIphone6PlusHasCorretName() {
15 | let iphone: Device = .iphone6Plus
16 | XCTAssertEqual(iphone.rawValue, "iPhone 6 Plus")
17 | }
18 |
19 | func testIphone6HasCorretName() {
20 | let iphone: Device = .iphone6
21 | XCTAssertEqual(iphone.rawValue, "iPhone 6")
22 | }
23 |
24 | // MARK: - Iphone 6s, 6s Plus
25 |
26 | func testIphone6sHasCorretName() {
27 | let iphone: Device = .iphone6s
28 | XCTAssertEqual(iphone.rawValue, "iPhone 6s")
29 | }
30 |
31 | func testIphone6sPlusHasCorretName() {
32 | let iphone: Device = .iphone6sPlus
33 | XCTAssertEqual(iphone.rawValue, "iPhone 6s Plus")
34 | }
35 |
36 | // MARK: - Iphone 7, 7 Plus
37 |
38 | func testIphone7HasCorretName() {
39 | let iphone: Device = .iphone7
40 | XCTAssertEqual(iphone.rawValue, "iPhone 7")
41 | }
42 |
43 | func testIphone7PlusHasCorretName() {
44 | let iphone: Device = .iphone7Plus
45 | XCTAssertEqual(iphone.rawValue, "iPhone 7 Plus")
46 | }
47 |
48 | // MARK: - Iphone 8, 8 Plus
49 |
50 | func testIphone8HasCorretName() {
51 | let iphone: Device = .iphone8
52 | XCTAssertEqual(iphone.rawValue, "iPhone 8")
53 | }
54 |
55 | func testIphone8PlusHasCorretName() {
56 | let iphone: Device = .iphone8Plus
57 | XCTAssertEqual(iphone.rawValue, "iPhone 8 Plus")
58 | }
59 |
60 | // MARK: - Iphone SE 1 Gen, SE 2 Gen, SE 3 Gen
61 |
62 | func testIphoneSE1GenHasCorretName() {
63 | let iphone: Device = .iphoneSE_1Gen
64 | XCTAssertEqual(iphone.rawValue, "iPhone SE (1st generation)")
65 | }
66 |
67 | func testIphoneSE2GenHasCorretName() {
68 | let iphone: Device = .iphoneSE_2Gen
69 | XCTAssertEqual(iphone.rawValue, "iPhone SE (2nd generation)")
70 | }
71 |
72 | func testIphoneSE3GenHasCorrectName() {
73 | let iphone: Device = .iphoneSE_3Gen
74 | XCTAssertEqual(iphone.rawValue, "iPhone SE (3rd generation)")
75 | }
76 |
77 | // MARK: - Iphone X, Xs, XsMax, Xr
78 |
79 | func testIphoneXHasCorretName() {
80 | let iphone: Device = .iphoneX
81 | XCTAssertEqual(iphone.rawValue, "iPhone X")
82 | }
83 |
84 | func testIphoneXsHasCorretName() {
85 | let iphone: Device = .iphoneXs
86 | XCTAssertEqual(iphone.rawValue, "iPhone Xs")
87 | }
88 |
89 | func testIphoneXsMaxHasCorretName() {
90 | let iphone: Device = .iphoneXsMax
91 | XCTAssertEqual(iphone.rawValue, "iPhone Xs Max")
92 | }
93 |
94 | func testIphoneXrHasCorretName() {
95 | let iphone: Device = .iphoneXr
96 | XCTAssertEqual(iphone.rawValue, "iPhone Xʀ")
97 | }
98 |
99 | // MARK: - Iphone 11, 11 Pro, 11 Pro Max
100 |
101 | func testIphone11HasCorretName() {
102 | let iphone: Device = .iphone11
103 | XCTAssertEqual(iphone.rawValue, "iPhone 11")
104 | }
105 |
106 | func testIphone11ProHasCorretName() {
107 | let iphone: Device = .iphone11Pro
108 | XCTAssertEqual(iphone.rawValue, "iPhone 11 Pro")
109 | }
110 |
111 | func testIphone11ProMaxHasCorretName() {
112 | let iphone: Device = .iphone11ProMax
113 | XCTAssertEqual(iphone.rawValue, "iPhone 11 Pro Max")
114 | }
115 |
116 | // MARK: - Iphone 12 mini, 12, 12 Pro, 12 Pro Max
117 |
118 | func testIphone12MiniHasCorretName() {
119 | let iphone: Device = .iphone12Mini
120 | XCTAssertEqual(iphone.rawValue, "iPhone 12 mini")
121 | }
122 |
123 | func testIphone12HasCorretName() {
124 | let iphone: Device = .iphone12
125 | XCTAssertEqual(iphone.rawValue, "iPhone 12")
126 | }
127 |
128 | func testIphone12ProHasCorretName() {
129 | let iphone: Device = .iphone12Pro
130 | XCTAssertEqual(iphone.rawValue, "iPhone 12 Pro")
131 | }
132 |
133 | func testIphone12ProMaxHasCorretName() {
134 | let iphone: Device = .iphone12ProMax
135 | XCTAssertEqual(iphone.rawValue, "iPhone 12 Pro Max")
136 | }
137 |
138 | // MARK: - Iphone 13 mini, 13, 13 Pro, 13 Pro Max
139 |
140 | func testIphone13MiniHasCorretName() {
141 | let iphone: Device = .iphone13Mini
142 | XCTAssertEqual(iphone.rawValue, "iPhone 13 mini")
143 | }
144 |
145 | func testIphone13HasCorretName() {
146 | let iphone: Device = .iphone13
147 | XCTAssertEqual(iphone.rawValue, "iPhone 13")
148 | }
149 |
150 | func testIphone13ProHasCorretName() {
151 | let iphone: Device = .iphone13Pro
152 | XCTAssertEqual(iphone.rawValue, "iPhone 13 Pro")
153 | }
154 |
155 | func testIphone13ProMaxHasCorretName() {
156 | let iphone: Device = .iphone13ProMax
157 | XCTAssertEqual(iphone.rawValue, "iPhone 13 Pro Max")
158 | }
159 |
160 | // MARK: - Iphone 14, 14 Plus, 14 Pro, 14 Pro Max
161 |
162 | func testIphone14HasCorrectName() {
163 | let iphone: Device = .iphone14
164 | XCTAssertEqual(iphone.rawValue, "iPhone 14")
165 | }
166 |
167 | func testIphone14PlusHasCorrectName() {
168 | let iphone: Device = .iphone14Plus
169 | XCTAssertEqual(iphone.rawValue, "iPhone 14 Plus")
170 | }
171 |
172 | func testIphone14ProHasCorrectName() {
173 | let iphone: Device = .iphone14Pro
174 | XCTAssertEqual(iphone.rawValue, "iPhone 14 Pro")
175 | }
176 |
177 | func testIphone14ProMaxHasCorrectName() {
178 | let iphone: Device = .iphone14ProMax
179 | XCTAssertEqual(iphone.rawValue, "iPhone 14 Pro Max")
180 | }
181 |
182 | // MARK: - Iphone 15, 15 Plus, 15 Pro, 15 Pro Max
183 |
184 | func testIphone15HasCorrectName() {
185 | let iphone: Device = .iphone15
186 | XCTAssertEqual(iphone.rawValue, "iPhone 15")
187 | }
188 |
189 | func testIphone15PlusHasCorrectName() {
190 | let iphone: Device = .iphone15Plus
191 | XCTAssertEqual(iphone.rawValue, "iPhone 15 Plus")
192 | }
193 |
194 | func testIphone15ProHasCorrectName() {
195 | let iphone: Device = .iphone15Pro
196 | XCTAssertEqual(iphone.rawValue, "iPhone 15 Pro")
197 | }
198 |
199 | func testIphone15ProMaxHasCorrectName() {
200 | let iphone: Device = .iphone15ProMax
201 | XCTAssertEqual(iphone.rawValue, "iPhone 15 Pro Max")
202 | }
203 | }
204 |
--------------------------------------------------------------------------------