@@ -48,7 +48,7 @@ import Foundation
48
48
/// showError()
49
49
/// }
50
50
///
51
- public enum Device {
51
+ public enum Device : Sendable {
52
52
#if os(iOS)
53
53
/// Device is an [iPod touch (5th generation)](https://support.apple.com/kb/SP657)
54
54
///
@@ -534,7 +534,7 @@ public enum Device {
534
534
}
535
535
536
536
/// Gets the identifier from the system, such as "iPhone7,1".
537
- public static var identifier : String = {
537
+ public static let identifier : String = {
538
538
var systemInfo = utsname ( )
539
539
uname ( & systemInfo)
540
540
let mirror = Mirror ( reflecting: systemInfo. machine)
@@ -1045,13 +1045,15 @@ public enum Device {
1045
1045
}
1046
1046
1047
1047
/// Returns whether the device is an iPhone (real or simulator)
1048
+ @MainActor
1048
1049
public var isPhone : Bool {
1049
1050
return ( isOneOf ( Device . allPhones)
1050
1051
|| isOneOf ( Device . allSimulatorPhones)
1051
1052
|| ( UIDevice . current. userInterfaceIdiom == . phone && isCurrent) ) && !isPod
1052
1053
}
1053
1054
1054
1055
/// Returns whether the device is an iPad (real or simulator)
1056
+ @MainActor
1055
1057
public var isPad : Bool {
1056
1058
return isOneOf ( Device . allPads)
1057
1059
|| isOneOf ( Device . allSimulatorPads)
@@ -1064,6 +1066,7 @@ public enum Device {
1064
1066
return Device . realDevice ( from: self )
1065
1067
}
1066
1068
1069
+ @MainActor
1067
1070
public var isZoomed : Bool ? {
1068
1071
guard isCurrent else { return nil }
1069
1072
if Int ( UIScreen . main. scale. rounded ( ) ) == 3 {
@@ -1300,6 +1303,9 @@ public enum Device {
1300
1303
/// The name identifying the device (e.g. "Dennis' iPhone").
1301
1304
/// As of iOS 16, this will return a generic String like "iPhone", unless your app has additional entitlements.
1302
1305
/// See the follwing link for more information: https://developer.apple.com/documentation/uikit/uidevice/1620015-name
1306
+ #if !os(watchOS) && canImport(UIKit)
1307
+ @MainActor
1308
+ #endif
1303
1309
public var name : String ? {
1304
1310
guard isCurrent else { return nil }
1305
1311
#if os(watchOS)
@@ -1312,6 +1318,9 @@ public enum Device {
1312
1318
}
1313
1319
1314
1320
/// The name of the operating system running on the device represented by the receiver (e.g. "iOS" or "tvOS").
1321
+ #if !os(watchOS) && (os(iOS) || canImport(UIKit))
1322
+ @MainActor
1323
+ #endif
1315
1324
public var systemName : String ? {
1316
1325
guard isCurrent else { return nil }
1317
1326
#if os(watchOS)
@@ -1330,6 +1339,9 @@ public enum Device {
1330
1339
}
1331
1340
1332
1341
/// The current version of the operating system (e.g. 8.4 or 9.2).
1342
+ #if !os(watchOS) && canImport(UIKit)
1343
+ @MainActor
1344
+ #endif
1333
1345
public var systemVersion : String ? {
1334
1346
guard isCurrent else { return nil }
1335
1347
#if os(watchOS)
@@ -1342,6 +1354,9 @@ public enum Device {
1342
1354
}
1343
1355
1344
1356
/// The model of the device (e.g. "iPhone" or "iPod Touch").
1357
+ #if !os(watchOS) && canImport(UIKit)
1358
+ @MainActor
1359
+ #endif
1345
1360
public var model : String ? {
1346
1361
guard isCurrent else { return nil }
1347
1362
#if os(watchOS)
@@ -1354,6 +1369,9 @@ public enum Device {
1354
1369
}
1355
1370
1356
1371
/// The model of the device as a localized string.
1372
+ #if !os(watchOS) && canImport(UIKit)
1373
+ @MainActor
1374
+ #endif
1357
1375
public var localizedModel : String ? {
1358
1376
guard isCurrent else { return nil }
1359
1377
#if os(watchOS)
@@ -1500,6 +1518,9 @@ public enum Device {
1500
1518
}
1501
1519
1502
1520
/// True when a Guided Access session is currently active; otherwise, false.
1521
+ #if os(iOS)
1522
+ @MainActor
1523
+ #endif
1503
1524
public var isGuidedAccessSessionActive : Bool {
1504
1525
#if os(iOS)
1505
1526
#if swift(>=4.2)
@@ -1513,6 +1534,9 @@ public enum Device {
1513
1534
}
1514
1535
1515
1536
/// The brightness level of the screen.
1537
+ #if os(iOS)
1538
+ @MainActor
1539
+ #endif
1516
1540
public var screenBrightness : Int {
1517
1541
#if os(iOS)
1518
1542
return Int ( UIScreen . main. brightness * 100 )
@@ -1844,7 +1868,7 @@ extension Device {
1844
1868
- Charging: The device is plugged into power and the battery is less than 100% charged.
1845
1869
- Unplugged: The device is not plugged into power; the battery is discharging.
1846
1870
*/
1847
- public enum BatteryState : CustomStringConvertible , Equatable {
1871
+ public enum BatteryState : CustomStringConvertible , Equatable , Sendable {
1848
1872
/// The device is plugged into power and the battery is 100% charged or the device is the iOS Simulator.
1849
1873
case full
1850
1874
/// The device is plugged into power and the battery is less than 100% charged.
@@ -1855,6 +1879,7 @@ extension Device {
1855
1879
case unplugged( Int )
1856
1880
1857
1881
#if os(iOS)
1882
+ @MainActor
1858
1883
fileprivate init ( ) {
1859
1884
let wasBatteryMonitoringEnabled = UIDevice . current. isBatteryMonitoringEnabled
1860
1885
UIDevice . current. isBatteryMonitoringEnabled = true
@@ -1911,12 +1936,18 @@ extension Device {
1911
1936
}
1912
1937
1913
1938
/// The state of the battery
1939
+ #if os(iOS)
1940
+ @MainActor
1941
+ #endif
1914
1942
public var batteryState : BatteryState ? {
1915
1943
guard isCurrent else { return nil }
1916
1944
return BatteryState ( )
1917
1945
}
1918
1946
1919
1947
/// Battery level ranges from 0 (fully discharged) to 100 (100% charged).
1948
+ #if os(iOS)
1949
+ @MainActor
1950
+ #endif
1920
1951
public var batteryLevel : Int ? {
1921
1952
guard isCurrent else { return nil }
1922
1953
switch BatteryState ( ) {
@@ -1972,16 +2003,18 @@ extension Device {
1972
2003
- Portrait: The device is in Portrait Orientation
1973
2004
- Unknown: The device orientation is unknown.
1974
2005
*/
1975
- public enum Orientation {
2006
+ public enum Orientation : Sendable {
1976
2007
case landscape
1977
2008
case portrait
1978
2009
case unknown
1979
2010
}
1980
2011
2012
+ @MainActor
1981
2013
public var orientation : Orientation {
1982
- if UIDevice . current. orientation. isLandscape {
2014
+ let orientation = UIDevice . current. orientation
2015
+ if orientation. isLandscape {
1983
2016
return . landscape
1984
- } else if UIDevice . current . orientation. isPortrait {
2017
+ } else if orientation. isPortrait {
1985
2018
return . portrait
1986
2019
} else {
1987
2020
return . unknown
@@ -2057,7 +2090,7 @@ extension Device {
2057
2090
- firstGenerationUsbC: 1st Generation Apple Pencil (USB-C)
2058
2091
- pro: Apple Pencil Pro
2059
2092
*/
2060
- public struct ApplePencilSupport : OptionSet {
2093
+ public struct ApplePencilSupport : OptionSet , Sendable {
2061
2094
2062
2095
public var rawValue : UInt
2063
2096
@@ -2117,7 +2150,7 @@ extension Device {
2117
2150
// MARK: Cameras
2118
2151
extension Device {
2119
2152
2120
- public enum CameraType {
2153
+ public enum CameraType : Sendable {
2121
2154
@available ( * , deprecated, renamed: " wide " )
2122
2155
case normal
2123
2156
@@ -2270,7 +2303,7 @@ extension Device {
2270
2303
}
2271
2304
#endif
2272
2305
2273
- // MARK: ThermalState
2306
+ // MARK: ThermalState: Sendable
2274
2307
@available ( iOS 11 . 0 , watchOS 4 . 0 , macOS 10 . 10 . 3 , tvOS 11 . 0 , * )
2275
2308
extension Device {
2276
2309
/// The thermal state of the system.
@@ -2307,7 +2340,7 @@ extension Device {
2307
2340
2308
2341
extension Device {
2309
2342
2310
- public enum CPU : Comparable {
2343
+ public enum CPU : Comparable , Sendable {
2311
2344
#if os(iOS) || os(tvOS)
2312
2345
case a4
2313
2346
case a5
0 commit comments