Skip to content

Commit 115bb72

Browse files
Added support for Strict Concurrency
1 parent 866ddd8 commit 115bb72

File tree

8 files changed

+156
-32
lines changed

8 files changed

+156
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ vendor
4545

4646
## Generated Files
4747
# *.generated.swift # we have to check it in because of CocoaPods ...
48+
Utils/__pycache__

DeviceKit.xcodeproj/project.pbxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,12 @@
396396
SUPPORTS_MACCATALYST = YES;
397397
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
398398
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
399-
SWIFT_VERSION = 5.0;
399+
SWIFT_VERSION = 6.0;
400400
TARGETED_DEVICE_FAMILY = "1,2,3,4,7";
401401
TVOS_DEPLOYMENT_TARGET = 13.0;
402402
VERSIONING_SYSTEM = "apple-generic";
403403
VERSION_INFO_PREFIX = "";
404-
WATCHOS_DEPLOYMENT_TARGET = 4.0;
404+
WATCHOS_DEPLOYMENT_TARGET = 6.0;
405405
};
406406
name = Debug;
407407
};
@@ -454,13 +454,13 @@
454454
SKIP_INSTALL = YES;
455455
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator watchos watchsimulator xros xrsimulator";
456456
SUPPORTS_MACCATALYST = YES;
457-
SWIFT_VERSION = 5.0;
457+
SWIFT_VERSION = 6.0;
458458
TARGETED_DEVICE_FAMILY = "1,2,3,4,7";
459459
TVOS_DEPLOYMENT_TARGET = 13.0;
460460
VALIDATE_PRODUCT = YES;
461461
VERSIONING_SYSTEM = "apple-generic";
462462
VERSION_INFO_PREFIX = "";
463-
WATCHOS_DEPLOYMENT_TARGET = 4.0;
463+
WATCHOS_DEPLOYMENT_TARGET = 6.0;
464464
};
465465
name = Release;
466466
};
@@ -506,7 +506,7 @@
506506
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
507507
SWIFT_OBJC_INTERFACE_HEADER_NAME = "";
508508
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
509-
SWIFT_VERSION = 5.0;
509+
SWIFT_VERSION = 6.0;
510510
TVOS_DEPLOYMENT_TARGET = 13.0;
511511
};
512512
name = Debug;
@@ -548,7 +548,7 @@
548548
SWIFT_COMPILATION_MODE = wholemodule;
549549
SWIFT_OBJC_INTERFACE_HEADER_NAME = "";
550550
SWIFT_OPTIMIZATION_LEVEL = "-O";
551-
SWIFT_VERSION = 5.0;
551+
SWIFT_VERSION = 6.0;
552552
TVOS_DEPLOYMENT_TARGET = 13.0;
553553
VALIDATE_PRODUCT = YES;
554554
};

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.3
1+
// swift-tools-version:6.0
22
//===----------------------------------------------------------------------===//
33
//
44
// This source file is part of the DeviceKit open source project
@@ -17,7 +17,7 @@ let package = Package(
1717
platforms: [
1818
.iOS(.v13),
1919
.tvOS(.v13),
20-
.watchOS(.v4)
20+
.watchOS(.v6)
2121
],
2222
products: [
2323
// Products define the executables and libraries produced by a package, and make them visible to other packages.
@@ -42,5 +42,5 @@ let package = Package(
4242
resources: [.process("../Source/PrivacyInfo.xcprivacy")]
4343
)
4444
],
45-
swiftLanguageVersions: [.v5]
45+
swiftLanguageModes: [.v5, .v6]
4646
)

Package@swift-5.6.swift

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// swift-tools-version:5.6
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// This source file is part of the DeviceKit open source project
5+
//
6+
// Copyright © 2014 - 2018 Dennis Weissmann and the DeviceKit project authors
7+
//
8+
// License: https://github.com/dennisweissmann/DeviceKit/blob/master/LICENSE
9+
// Contributors: https://github.com/dennisweissmann/DeviceKit#contributors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import PackageDescription
14+
15+
let package = Package(
16+
name: "DeviceKit",
17+
platforms: [
18+
.iOS(.v13),
19+
.tvOS(.v13),
20+
.watchOS(.v6)
21+
],
22+
products: [
23+
// Products define the executables and libraries produced by a package, and make them visible to other packages.
24+
.library(
25+
name: "DeviceKit",
26+
targets: ["DeviceKit"]
27+
)
28+
],
29+
targets: [
30+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
31+
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
32+
.target(
33+
name: "DeviceKit",
34+
dependencies: [],
35+
path: "Source",
36+
resources: [.process("PrivacyInfo.xcprivacy")],
37+
swiftSettings: [
38+
.enableExperimentalFeature("StrictConcurrency"),
39+
]
40+
),
41+
.testTarget(
42+
name: "DeviceKitTests",
43+
dependencies: ["DeviceKit"],
44+
path: "Tests",
45+
resources: [.process("../Source/PrivacyInfo.xcprivacy")],
46+
swiftSettings: [
47+
.enableExperimentalFeature("StrictConcurrency"),
48+
]
49+
)
50+
],
51+
swiftLanguageVersions: [.v5]
52+
)

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ See our detailed [changelog](CHANGELOG.md) for the latest features, improvements
4141

4242
## Requirements
4343

44-
- iOS 11.0+
45-
- tvOS 11.0+
46-
- watchOS 4.0+
44+
- iOS 13.0+
45+
- tvOS 13.0+
46+
- watchOS 6.0+
4747

4848
## Installation
4949
DeviceKit can be installed in various ways.

Source/Device.generated.swift

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
21182151
extension 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, *)
22752308
extension Device {
22762309
/// The thermal state of the system.
@@ -2307,7 +2340,7 @@ extension Device {
23072340

23082341
extension 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

Comments
 (0)