@@ -48,7 +48,7 @@ import Foundation
4848/// showError()
4949/// }
5050///
51- public enum Device {
51+ public enum Device : Sendable {
5252 #if os(iOS)
5353 /// Device is an [iPod touch (5th generation)](https://support.apple.com/kb/SP657)
5454 ///
@@ -534,7 +534,7 @@ public enum Device {
534534 }
535535
536536 /// Gets the identifier from the system, such as "iPhone7,1".
537- public static var identifier : String = {
537+ public static let identifier : String = {
538538 var systemInfo = utsname ( )
539539 uname ( & systemInfo)
540540 let mirror = Mirror ( reflecting: systemInfo. machine)
@@ -1045,13 +1045,15 @@ public enum Device {
10451045 }
10461046
10471047 /// Returns whether the device is an iPhone (real or simulator)
1048+ @MainActor
10481049 public var isPhone : Bool {
10491050 return ( isOneOf ( Device . allPhones)
10501051 || isOneOf ( Device . allSimulatorPhones)
10511052 || ( UIDevice . current. userInterfaceIdiom == . phone && isCurrent) ) && !isPod
10521053 }
10531054
10541055 /// Returns whether the device is an iPad (real or simulator)
1056+ @MainActor
10551057 public var isPad : Bool {
10561058 return isOneOf ( Device . allPads)
10571059 || isOneOf ( Device . allSimulatorPads)
@@ -1064,6 +1066,7 @@ public enum Device {
10641066 return Device . realDevice ( from: self )
10651067 }
10661068
1069+ @MainActor
10671070 public var isZoomed : Bool ? {
10681071 guard isCurrent else { return nil }
10691072 if Int ( UIScreen . main. scale. rounded ( ) ) == 3 {
@@ -1300,6 +1303,9 @@ public enum Device {
13001303 /// The name identifying the device (e.g. "Dennis' iPhone").
13011304 /// As of iOS 16, this will return a generic String like "iPhone", unless your app has additional entitlements.
13021305 /// 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
13031309 public var name : String ? {
13041310 guard isCurrent else { return nil }
13051311 #if os(watchOS)
@@ -1312,6 +1318,9 @@ public enum Device {
13121318 }
13131319
13141320 /// 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
13151324 public var systemName : String ? {
13161325 guard isCurrent else { return nil }
13171326 #if os(watchOS)
@@ -1330,6 +1339,9 @@ public enum Device {
13301339 }
13311340
13321341 /// The current version of the operating system (e.g. 8.4 or 9.2).
1342+ #if !os(watchOS) && canImport(UIKit)
1343+ @MainActor
1344+ #endif
13331345 public var systemVersion : String ? {
13341346 guard isCurrent else { return nil }
13351347 #if os(watchOS)
@@ -1342,6 +1354,9 @@ public enum Device {
13421354 }
13431355
13441356 /// The model of the device (e.g. "iPhone" or "iPod Touch").
1357+ #if !os(watchOS) && canImport(UIKit)
1358+ @MainActor
1359+ #endif
13451360 public var model : String ? {
13461361 guard isCurrent else { return nil }
13471362 #if os(watchOS)
@@ -1354,6 +1369,9 @@ public enum Device {
13541369 }
13551370
13561371 /// The model of the device as a localized string.
1372+ #if !os(watchOS) && canImport(UIKit)
1373+ @MainActor
1374+ #endif
13571375 public var localizedModel : String ? {
13581376 guard isCurrent else { return nil }
13591377 #if os(watchOS)
@@ -1500,6 +1518,9 @@ public enum Device {
15001518 }
15011519
15021520 /// True when a Guided Access session is currently active; otherwise, false.
1521+ #if os(iOS)
1522+ @MainActor
1523+ #endif
15031524 public var isGuidedAccessSessionActive : Bool {
15041525 #if os(iOS)
15051526 #if swift(>=4.2)
@@ -1513,6 +1534,9 @@ public enum Device {
15131534 }
15141535
15151536 /// The brightness level of the screen.
1537+ #if os(iOS)
1538+ @MainActor
1539+ #endif
15161540 public var screenBrightness : Int {
15171541 #if os(iOS)
15181542 return Int ( UIScreen . main. brightness * 100 )
@@ -1844,7 +1868,7 @@ extension Device {
18441868 - Charging: The device is plugged into power and the battery is less than 100% charged.
18451869 - Unplugged: The device is not plugged into power; the battery is discharging.
18461870 */
1847- public enum BatteryState : CustomStringConvertible , Equatable {
1871+ public enum BatteryState : CustomStringConvertible , Equatable , Sendable {
18481872 /// The device is plugged into power and the battery is 100% charged or the device is the iOS Simulator.
18491873 case full
18501874 /// The device is plugged into power and the battery is less than 100% charged.
@@ -1855,6 +1879,7 @@ extension Device {
18551879 case unplugged( Int )
18561880
18571881 #if os(iOS)
1882+ @MainActor
18581883 fileprivate init ( ) {
18591884 let wasBatteryMonitoringEnabled = UIDevice . current. isBatteryMonitoringEnabled
18601885 UIDevice . current. isBatteryMonitoringEnabled = true
@@ -1911,12 +1936,18 @@ extension Device {
19111936 }
19121937
19131938 /// The state of the battery
1939+ #if os(iOS)
1940+ @MainActor
1941+ #endif
19141942 public var batteryState : BatteryState ? {
19151943 guard isCurrent else { return nil }
19161944 return BatteryState ( )
19171945 }
19181946
19191947 /// Battery level ranges from 0 (fully discharged) to 100 (100% charged).
1948+ #if os(iOS)
1949+ @MainActor
1950+ #endif
19201951 public var batteryLevel : Int ? {
19211952 guard isCurrent else { return nil }
19221953 switch BatteryState ( ) {
@@ -1972,16 +2003,18 @@ extension Device {
19722003 - Portrait: The device is in Portrait Orientation
19732004 - Unknown: The device orientation is unknown.
19742005 */
1975- public enum Orientation {
2006+ public enum Orientation : Sendable {
19762007 case landscape
19772008 case portrait
19782009 case unknown
19792010 }
19802011
2012+ @MainActor
19812013 public var orientation : Orientation {
1982- if UIDevice . current. orientation. isLandscape {
2014+ let orientation = UIDevice . current. orientation
2015+ if orientation. isLandscape {
19832016 return . landscape
1984- } else if UIDevice . current . orientation. isPortrait {
2017+ } else if orientation. isPortrait {
19852018 return . portrait
19862019 } else {
19872020 return . unknown
@@ -2057,7 +2090,7 @@ extension Device {
20572090 - firstGenerationUsbC: 1st Generation Apple Pencil (USB-C)
20582091 - pro: Apple Pencil Pro
20592092 */
2060- public struct ApplePencilSupport : OptionSet {
2093+ public struct ApplePencilSupport : OptionSet , Sendable {
20612094
20622095 public var rawValue : UInt
20632096
@@ -2117,7 +2150,7 @@ extension Device {
21172150// MARK: Cameras
21182151extension Device {
21192152
2120- public enum CameraType {
2153+ public enum CameraType : Sendable {
21212154 @available ( * , deprecated, renamed: " wide " )
21222155 case normal
21232156
@@ -2270,7 +2303,7 @@ extension Device {
22702303}
22712304#endif
22722305
2273- // MARK: ThermalState
2306+ // MARK: ThermalState: Sendable
22742307@available ( iOS 11 . 0 , watchOS 4 . 0 , macOS 10 . 10 . 3 , tvOS 11 . 0 , * )
22752308extension Device {
22762309 /// The thermal state of the system.
@@ -2307,7 +2340,7 @@ extension Device {
23072340
23082341extension Device {
23092342
2310- public enum CPU : Comparable {
2343+ public enum CPU : Comparable , Sendable {
23112344 #if os(iOS) || os(tvOS)
23122345 case a4
23132346 case a5
0 commit comments