Skip to content

Added support for Swift 6 / Strict Concurrency #437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ vendor

## Generated Files
# *.generated.swift # we have to check it in because of CocoaPods ...
Utils/__pycache__
12 changes: 6 additions & 6 deletions DeviceKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,12 @@
SUPPORTS_MACCATALYST = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4,7";
TVOS_DEPLOYMENT_TARGET = 13.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
WATCHOS_DEPLOYMENT_TARGET = 4.0;
WATCHOS_DEPLOYMENT_TARGET = 6.0;
};
name = Debug;
};
Expand Down Expand Up @@ -454,13 +454,13 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator watchos watchsimulator xros xrsimulator";
SUPPORTS_MACCATALYST = YES;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4,7";
TVOS_DEPLOYMENT_TARGET = 13.0;
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
WATCHOS_DEPLOYMENT_TARGET = 4.0;
WATCHOS_DEPLOYMENT_TARGET = 6.0;
};
name = Release;
};
Expand Down Expand Up @@ -506,7 +506,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OBJC_INTERFACE_HEADER_NAME = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TVOS_DEPLOYMENT_TARGET = 13.0;
};
name = Debug;
Expand Down Expand Up @@ -548,7 +548,7 @@
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OBJC_INTERFACE_HEADER_NAME = "";
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TVOS_DEPLOYMENT_TARGET = 13.0;
VALIDATE_PRODUCT = YES;
};
Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the DeviceKit open source project
Expand All @@ -17,7 +17,7 @@ let package = Package(
platforms: [
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v4)
.watchOS(.v6)
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
Expand All @@ -42,5 +42,5 @@ let package = Package(
resources: [.process("../Source/PrivacyInfo.xcprivacy")]
)
],
swiftLanguageVersions: [.v5]
swiftLanguageModes: [.v5, .v6]
)
52 changes: 52 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// swift-tools-version:5.6
//===----------------------------------------------------------------------===//
//
// This source file is part of the DeviceKit open source project
//
// Copyright © 2014 - 2018 Dennis Weissmann and the DeviceKit project authors
//
// License: https://github.com/dennisweissmann/DeviceKit/blob/master/LICENSE
// Contributors: https://github.com/dennisweissmann/DeviceKit#contributors
//
//===----------------------------------------------------------------------===//

import PackageDescription

let package = Package(
name: "DeviceKit",
platforms: [
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v6)
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "DeviceKit",
targets: ["DeviceKit"]
)
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "DeviceKit",
dependencies: [],
path: "Source",
resources: [.process("PrivacyInfo.xcprivacy")],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
),
.testTarget(
name: "DeviceKitTests",
dependencies: ["DeviceKit"],
path: "Tests",
resources: [.process("../Source/PrivacyInfo.xcprivacy")],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
)
],
swiftLanguageVersions: [.v5]
)
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ See our detailed [changelog](CHANGELOG.md) for the latest features, improvements

## Requirements

- iOS 11.0+
- tvOS 11.0+
- watchOS 4.0+
- iOS 13.0+
- tvOS 13.0+
- watchOS 6.0+

## Installation
DeviceKit can be installed in various ways.
Expand Down
51 changes: 42 additions & 9 deletions Source/Device.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import Foundation
/// showError()
/// }
///
public enum Device {
public enum Device: Sendable {
#if os(iOS)
/// Device is an [iPod touch (5th generation)](https://support.apple.com/kb/SP657)
///
Expand Down Expand Up @@ -550,7 +550,7 @@ public enum Device {
}

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

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

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

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

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

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

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

/// The model of the device as a localized string.
#if !os(watchOS) && canImport(UIKit)
@MainActor
#endif
public var localizedModel: String? {
guard isCurrent else { return nil }
#if os(watchOS)
Expand Down Expand Up @@ -1532,6 +1550,9 @@ public enum Device {
}

/// True when a Guided Access session is currently active; otherwise, false.
#if os(iOS)
@MainActor
#endif
public var isGuidedAccessSessionActive: Bool {
#if os(iOS)
#if swift(>=4.2)
Expand All @@ -1545,6 +1566,9 @@ public enum Device {
}

/// The brightness level of the screen.
#if os(iOS)
@MainActor
#endif
public var screenBrightness: Int {
#if os(iOS)
return Int(UIScreen.main.brightness * 100)
Expand Down Expand Up @@ -1884,7 +1908,7 @@ extension Device {
- Charging: The device is plugged into power and the battery is less than 100% charged.
- Unplugged: The device is not plugged into power; the battery is discharging.
*/
public enum BatteryState: CustomStringConvertible, Equatable {
public enum BatteryState: CustomStringConvertible, Equatable, Sendable {
/// The device is plugged into power and the battery is 100% charged or the device is the iOS Simulator.
case full
/// The device is plugged into power and the battery is less than 100% charged.
Expand All @@ -1895,6 +1919,7 @@ extension Device {
case unplugged(Int)

#if os(iOS)
@MainActor
fileprivate init() {
let wasBatteryMonitoringEnabled = UIDevice.current.isBatteryMonitoringEnabled
UIDevice.current.isBatteryMonitoringEnabled = true
Expand Down Expand Up @@ -1951,12 +1976,18 @@ extension Device {
}

/// The state of the battery
#if os(iOS)
@MainActor
#endif
public var batteryState: BatteryState? {
guard isCurrent else { return nil }
return BatteryState()
}

/// Battery level ranges from 0 (fully discharged) to 100 (100% charged).
#if os(iOS)
@MainActor
#endif
public var batteryLevel: Int? {
guard isCurrent else { return nil }
switch BatteryState() {
Expand Down Expand Up @@ -2012,16 +2043,18 @@ extension Device {
- Portrait: The device is in Portrait Orientation
- Unknown: The device orientation is unknown.
*/
public enum Orientation {
public enum Orientation: Sendable {
case landscape
case portrait
case unknown
}

@MainActor
public var orientation: Orientation {
if UIDevice.current.orientation.isLandscape {
let orientation = UIDevice.current.orientation
if orientation.isLandscape {
return .landscape
} else if UIDevice.current.orientation.isPortrait {
} else if orientation.isPortrait {
return .portrait
} else {
return .unknown
Expand Down Expand Up @@ -2097,7 +2130,7 @@ extension Device {
- firstGenerationUsbC: 1st Generation Apple Pencil (USB-C)
- pro: Apple Pencil Pro
*/
public struct ApplePencilSupport: OptionSet {
public struct ApplePencilSupport: OptionSet, Sendable {

public var rawValue: UInt

Expand Down Expand Up @@ -2160,7 +2193,7 @@ extension Device {
// MARK: Cameras
extension Device {

public enum CameraType {
public enum CameraType: Sendable {
@available(*, deprecated, renamed: "wide")
case normal

Expand Down Expand Up @@ -2354,7 +2387,7 @@ extension Device {

extension Device {

public enum CPU: Comparable {
public enum CPU: Comparable, Sendable {
#if os(iOS) || os(tvOS)
case a4
case a5
Expand Down
Loading
Loading