Skip to content

Commit 14134d7

Browse files
SomeRandomiOSDevZandor300
authored andcommitted
Added support for Strict Concurrency
1 parent 511b286 commit 14134d7

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
)

[email protected]

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
///
@@ -550,7 +550,7 @@ public enum Device {
550550
}
551551

552552
/// Gets the identifier from the system, such as "iPhone7,1".
553-
public static var identifier: String = {
553+
public static let identifier: String = {
554554
var systemInfo = utsname()
555555
uname(&systemInfo)
556556
let mirror = Mirror(reflecting: systemInfo.machine)
@@ -1073,13 +1073,15 @@ public enum Device {
10731073
}
10741074

10751075
/// Returns whether the device is an iPhone (real or simulator)
1076+
@MainActor
10761077
public var isPhone: Bool {
10771078
return (isOneOf(Device.allPhones)
10781079
|| isOneOf(Device.allSimulatorPhones)
10791080
|| (UIDevice.current.userInterfaceIdiom == .phone && isCurrent)) && !isPod
10801081
}
10811082

10821083
/// Returns whether the device is an iPad (real or simulator)
1084+
@MainActor
10831085
public var isPad: Bool {
10841086
return isOneOf(Device.allPads)
10851087
|| isOneOf(Device.allSimulatorPads)
@@ -1092,6 +1094,7 @@ public enum Device {
10921094
return Device.realDevice(from: self)
10931095
}
10941096

1097+
@MainActor
10951098
public var isZoomed: Bool? {
10961099
guard isCurrent else { return nil }
10971100
if Int(UIScreen.main.scale.rounded()) == 3 {
@@ -1328,6 +1331,9 @@ public enum Device {
13281331
/// The name identifying the device (e.g. "Dennis' iPhone").
13291332
/// As of iOS 16, this will return a generic String like "iPhone", unless your app has additional entitlements.
13301333
/// See the follwing link for more information: https://developer.apple.com/documentation/uikit/uidevice/1620015-name
1334+
#if !os(watchOS) && canImport(UIKit)
1335+
@MainActor
1336+
#endif
13311337
public var name: String? {
13321338
guard isCurrent else { return nil }
13331339
#if os(watchOS)
@@ -1340,6 +1346,9 @@ public enum Device {
13401346
}
13411347

13421348
/// The name of the operating system running on the device represented by the receiver (e.g. "iOS" or "tvOS").
1349+
#if !os(watchOS) && (os(iOS) || canImport(UIKit))
1350+
@MainActor
1351+
#endif
13431352
public var systemName: String? {
13441353
guard isCurrent else { return nil }
13451354
#if os(watchOS)
@@ -1358,6 +1367,9 @@ public enum Device {
13581367
}
13591368

13601369
/// The current version of the operating system (e.g. 8.4 or 9.2).
1370+
#if !os(watchOS) && canImport(UIKit)
1371+
@MainActor
1372+
#endif
13611373
public var systemVersion: String? {
13621374
guard isCurrent else { return nil }
13631375
#if os(watchOS)
@@ -1370,6 +1382,9 @@ public enum Device {
13701382
}
13711383

13721384
/// The model of the device (e.g. "iPhone" or "iPod Touch").
1385+
#if !os(watchOS) && canImport(UIKit)
1386+
@MainActor
1387+
#endif
13731388
public var model: String? {
13741389
guard isCurrent else { return nil }
13751390
#if os(watchOS)
@@ -1382,6 +1397,9 @@ public enum Device {
13821397
}
13831398

13841399
/// The model of the device as a localized string.
1400+
#if !os(watchOS) && canImport(UIKit)
1401+
@MainActor
1402+
#endif
13851403
public var localizedModel: String? {
13861404
guard isCurrent else { return nil }
13871405
#if os(watchOS)
@@ -1532,6 +1550,9 @@ public enum Device {
15321550
}
15331551

15341552
/// True when a Guided Access session is currently active; otherwise, false.
1553+
#if os(iOS)
1554+
@MainActor
1555+
#endif
15351556
public var isGuidedAccessSessionActive: Bool {
15361557
#if os(iOS)
15371558
#if swift(>=4.2)
@@ -1545,6 +1566,9 @@ public enum Device {
15451566
}
15461567

15471568
/// The brightness level of the screen.
1569+
#if os(iOS)
1570+
@MainActor
1571+
#endif
15481572
public var screenBrightness: Int {
15491573
#if os(iOS)
15501574
return Int(UIScreen.main.brightness * 100)
@@ -1884,7 +1908,7 @@ extension Device {
18841908
- Charging: The device is plugged into power and the battery is less than 100% charged.
18851909
- Unplugged: The device is not plugged into power; the battery is discharging.
18861910
*/
1887-
public enum BatteryState: CustomStringConvertible, Equatable {
1911+
public enum BatteryState: CustomStringConvertible, Equatable, Sendable {
18881912
/// The device is plugged into power and the battery is 100% charged or the device is the iOS Simulator.
18891913
case full
18901914
/// The device is plugged into power and the battery is less than 100% charged.
@@ -1895,6 +1919,7 @@ extension Device {
18951919
case unplugged(Int)
18961920

18971921
#if os(iOS)
1922+
@MainActor
18981923
fileprivate init() {
18991924
let wasBatteryMonitoringEnabled = UIDevice.current.isBatteryMonitoringEnabled
19001925
UIDevice.current.isBatteryMonitoringEnabled = true
@@ -1951,12 +1976,18 @@ extension Device {
19511976
}
19521977

19531978
/// The state of the battery
1979+
#if os(iOS)
1980+
@MainActor
1981+
#endif
19541982
public var batteryState: BatteryState? {
19551983
guard isCurrent else { return nil }
19561984
return BatteryState()
19571985
}
19581986

19591987
/// Battery level ranges from 0 (fully discharged) to 100 (100% charged).
1988+
#if os(iOS)
1989+
@MainActor
1990+
#endif
19601991
public var batteryLevel: Int? {
19611992
guard isCurrent else { return nil }
19621993
switch BatteryState() {
@@ -2012,16 +2043,18 @@ extension Device {
20122043
- Portrait: The device is in Portrait Orientation
20132044
- Unknown: The device orientation is unknown.
20142045
*/
2015-
public enum Orientation {
2046+
public enum Orientation: Sendable {
20162047
case landscape
20172048
case portrait
20182049
case unknown
20192050
}
20202051

2052+
@MainActor
20212053
public var orientation: Orientation {
2022-
if UIDevice.current.orientation.isLandscape {
2054+
let orientation = UIDevice.current.orientation
2055+
if orientation.isLandscape {
20232056
return .landscape
2024-
} else if UIDevice.current.orientation.isPortrait {
2057+
} else if orientation.isPortrait {
20252058
return .portrait
20262059
} else {
20272060
return .unknown
@@ -2097,7 +2130,7 @@ extension Device {
20972130
- firstGenerationUsbC: 1st Generation Apple Pencil (USB-C)
20982131
- pro: Apple Pencil Pro
20992132
*/
2100-
public struct ApplePencilSupport: OptionSet {
2133+
public struct ApplePencilSupport: OptionSet, Sendable {
21012134

21022135
public var rawValue: UInt
21032136

@@ -2160,7 +2193,7 @@ extension Device {
21602193
// MARK: Cameras
21612194
extension Device {
21622195

2163-
public enum CameraType {
2196+
public enum CameraType: Sendable {
21642197
@available(*, deprecated, renamed: "wide")
21652198
case normal
21662199

@@ -2317,7 +2350,7 @@ extension Device {
23172350
}
23182351
#endif
23192352

2320-
// MARK: ThermalState
2353+
// MARK: ThermalState: Sendable
23212354
@available(iOS 11.0, watchOS 4.0, macOS 10.10.3, tvOS 11.0, *)
23222355
extension Device {
23232356
/// The thermal state of the system.
@@ -2354,7 +2387,7 @@ extension Device {
23542387

23552388
extension Device {
23562389

2357-
public enum CPU: Comparable {
2390+
public enum CPU: Comparable, Sendable {
23582391
#if os(iOS) || os(tvOS)
23592392
case a4
23602393
case a5

0 commit comments

Comments
 (0)