From ec0c49775ba7271c0b83d87f5376822af5431e1a Mon Sep 17 00:00:00 2001 From: Mark Battistella Date: Sat, 3 Aug 2024 16:29:24 +1000 Subject: [PATCH] 2024-08-03 - Swift 6 Concurrency --- Package.swift | 14 ++++++-------- Sources/BezelKit/BezelKit.swift | 9 +++++---- Sources/BezelKit/CGFloat+Ext.swift | 3 ++- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Package.swift b/Package.swift index 4090f2e..97dbbd8 100644 --- a/Package.swift +++ b/Package.swift @@ -1,15 +1,10 @@ -// swift-tools-version: 5.4 -// -// Project: BezelKit -// Author: Mark Battistella -// Website: https://markbattistella.com -// +// swift-tools-version: 5.10 import PackageDescription let package = Package( name: "BezelKit", - platforms: [.iOS(.v11)], + platforms: [.iOS(.v12)], products: [ .library( name: "BezelKit", @@ -21,7 +16,10 @@ let package = Package( .target( name: "BezelKit", exclude: ["../../Generator"], - resources: [.process("Resources/bezel.min.json")] + resources: [.process("Resources/bezel.min.json")], + swiftSettings: [ + .enableExperimentalFeature("StrictConcurrency") + ] ) ] ) diff --git a/Sources/BezelKit/BezelKit.swift b/Sources/BezelKit/BezelKit.swift index 293a40e..e522c4b 100644 --- a/Sources/BezelKit/BezelKit.swift +++ b/Sources/BezelKit/BezelKit.swift @@ -7,6 +7,7 @@ import UIKit /// `DeviceBezel` provides a mechanism to obtain the bezel radius of the current device. +@MainActor public class DeviceBezel { /// An enumeration of errors that can occur when attempting to obtain a device's bezel thickness. @@ -22,18 +23,18 @@ public class DeviceBezel { } /// Cache to hold parsed device information. - private static var devices: Devices? + private static var devices: Devices? /// A cache mapping device identifiers to their respective bezel thicknesses. - private static var cache: [String: CGFloat] = [:] + private static var cache: [String: CGFloat] = [:] /// A callback to be invoked when an error occurs during bezel data fetching or processing. - public static var errorCallback: ((DeviceBezelError) -> Void)? + public static var errorCallback: ((DeviceBezelError) -> Void)? /// Loads device data from the JSON resource, decoding and caching the relevant information. /// /// - Throws: An error of type `DeviceBezelError` if there's an issue accessing or decoding the data. - private static func loadDeviceData() throws { + private static func loadDeviceData() throws { guard let url = Bundle.module.url( forResource: "bezel", withExtension: "min.json" diff --git a/Sources/BezelKit/CGFloat+Ext.swift b/Sources/BezelKit/CGFloat+Ext.swift index 81bee1c..2bf5f46 100644 --- a/Sources/BezelKit/CGFloat+Ext.swift +++ b/Sources/BezelKit/CGFloat+Ext.swift @@ -6,8 +6,9 @@ import Foundation +@MainActor public extension CGFloat { - + /// A fallback value used when the device bezel radius cannot be determined. private static var fallbackBezelValue: CGFloat = 0.0