Skip to content

Commit

Permalink
Fixes for Swift 6 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
orchetect committed Oct 14, 2024
1 parent edf22f4 commit eb9e5dd
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Sources/TimecodeKit/Timecode/Encoding/NSItemProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ extension NSItemProvider {
@MainActor
fileprivate func _loadTransferable<T>(
type transferableType: T.Type
) async throws -> T where T: Transferable {
) async throws -> T where T: Transferable, T: Sendable {
let result = await withCheckedContinuation { continuation in
// discard the returned Progress instance
_ = loadTransferable(type: transferableType) { result in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/// A protocol for timecode time value sources that do not supply their own frame
/// rate information.
protocol _TimecodeSource {
protocol _TimecodeSource where Self: Sendable {
/// Sets the timecode for a ``Timecode`` instance from a time value source.
/// Not meant to be called directly; instead, pass this instance into a ``Timecode`` initializer.
func set(timecode: inout Timecode) throws
Expand All @@ -20,7 +20,7 @@ protocol _TimecodeSource {

/// A protocol for timecode time value sources that do not supply their own frame
/// rate information. (Async variant of ``_TimecodeSource``.)
protocol _AsyncTimecodeSource {
protocol _AsyncTimecodeSource where Self: Sendable {
/// Sets the timecode for a ``Timecode`` instance from a time value source.
/// Not meant to be called directly; instead, pass this instance into a ``Timecode`` initializer.
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
Expand All @@ -34,7 +34,7 @@ protocol _AsyncTimecodeSource {

/// A protocol for formatted timecode time value sources that do not supply their own frame
/// rate information.
protocol _FormattedTimecodeSource {
protocol _FormattedTimecodeSource where Self: Sendable {
/// Sets the timecode for a ``Timecode`` instance from a time value source.
/// Not meant to be called directly; instead, pass this instance into a ``Timecode`` initializer.
func set(timecode: inout Timecode) throws
Expand All @@ -45,7 +45,7 @@ protocol _FormattedTimecodeSource {
}

/// A protocol for timecode time value sources that are able to supply frame rate information.
protocol _RichTimecodeSource {
protocol _RichTimecodeSource where Self: Sendable {
/// Sets the timecode for a ``Timecode`` instance from a time value source.
/// Not meant to be called directly; instead, pass this instance into a ``Timecode`` initializer.
func set(timecode: inout Timecode) throws -> Timecode.Properties
Expand All @@ -57,23 +57,23 @@ protocol _RichTimecodeSource {

/// A protocol for timecode time value sources that are able to supply frame rate information.
/// (Async variant of ``_RichTimecodeSource``.)
protocol _AsyncRichTimecodeSource {
protocol _AsyncRichTimecodeSource where Self: Sendable {
/// Sets the timecode for a ``Timecode`` instance from a time value source.
/// Not meant to be called directly; instead, pass this instance into a ``Timecode`` initializer.
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func set(timecode: inout Timecode) async throws -> Timecode.Properties
}

/// A protocol for timecode time value sources that are guaranteed to be valid regardless of properties.
protocol _GuaranteedTimecodeSource {
protocol _GuaranteedTimecodeSource where Self: Sendable {
/// Sets the timecode for a ``Timecode`` instance from a time value source.
/// Not meant to be called directly; instead, pass this instance into a ``Timecode`` initializer.
func set(timecode: inout Timecode)
}

/// A protocol for timecode time value sources that are able to supply frame rate information and
/// are guaranteed to be valid regardless of properties.
protocol _GuaranteedRichTimecodeSource {
protocol _GuaranteedRichTimecodeSource where Self: Sendable {
/// Sets the timecode for a ``Timecode`` instance from a time value source.
/// Not meant to be called directly; instead, pass this instance into a ``Timecode`` initializer.
func set(timecode: inout Timecode) -> Timecode.Properties
Expand All @@ -87,7 +87,7 @@ protocol _GuaranteedRichTimecodeSource {
/// > This struct is not designed to be used directly. Use the static construction methods to form a value instead.
/// > See ``Timecode`` for more details and examples.
@_documentation(visibility: internal)
public struct TimecodeSourceValue {
public struct TimecodeSourceValue: Sendable {
var value: _TimecodeSource

init(value: _TimecodeSource) {
Expand All @@ -102,7 +102,7 @@ public struct TimecodeSourceValue {
/// > This struct is not designed to be used directly. Use the static construction methods to form a value instead.
/// > See ``Timecode`` for more details and examples.
@_documentation(visibility: internal)
public struct AsyncTimecodeSourceValue {
public struct AsyncTimecodeSourceValue: Sendable {
var value: _AsyncTimecodeSource

init(value: _AsyncTimecodeSource) {
Expand All @@ -116,7 +116,7 @@ public struct AsyncTimecodeSourceValue {
/// > This struct is not designed to be used directly. Use the static construction methods to form a value instead.
/// > See ``Timecode`` for more details and examples.
@_documentation(visibility: internal)
public struct FormattedTimecodeSourceValue {
public struct FormattedTimecodeSourceValue: Sendable {
var value: _FormattedTimecodeSource

init(value: _FormattedTimecodeSource) {
Expand All @@ -130,7 +130,7 @@ public struct FormattedTimecodeSourceValue {
/// > This struct is not designed to be used directly. Use the static construction methods to form a value instead.
/// > See ``Timecode`` for more details and examples.
@_documentation(visibility: internal)
public struct RichTimecodeSourceValue {
public struct RichTimecodeSourceValue: Sendable {
var value: _RichTimecodeSource

init(value: _RichTimecodeSource) {
Expand All @@ -145,7 +145,7 @@ public struct RichTimecodeSourceValue {
/// > This struct is not designed to be used directly. Use the static construction methods to form a value instead.
/// > See ``Timecode`` for more details and examples.
@_documentation(visibility: internal)
public struct AsyncRichTimecodeSourceValue {
public struct AsyncRichTimecodeSourceValue: Sendable {
var value: _AsyncRichTimecodeSource

init(value: _AsyncRichTimecodeSource) {
Expand All @@ -159,7 +159,7 @@ public struct AsyncRichTimecodeSourceValue {
/// > This struct is not designed to be used directly. Use the static construction methods to form a value instead.
/// > See ``Timecode`` for more details and examples.
@_documentation(visibility: internal)
public struct GuaranteedTimecodeSourceValue {
public struct GuaranteedTimecodeSourceValue: Sendable {
var value: _GuaranteedTimecodeSource

init(value: _GuaranteedTimecodeSource) {
Expand All @@ -173,7 +173,7 @@ public struct GuaranteedTimecodeSourceValue {
/// > This struct is not designed to be used directly. Use the static construction methods to form a value instead.
/// > See ``Timecode`` for more details and examples.
@_documentation(visibility: internal)
public struct GuaranteedRichTimecodeSourceValue {
public struct GuaranteedRichTimecodeSourceValue: Sendable {
var value: _GuaranteedRichTimecodeSource

init(value: _GuaranteedRichTimecodeSource) {
Expand Down
10 changes: 5 additions & 5 deletions Sources/TimecodeKit/Timecode/Source/Timecode AVAsset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
// AVAssetReader is unavailable on watchOS so we can't support any AVAsset operations
#if canImport(AVFoundation) && !os(watchOS) && !os(visionOS)

import AVFoundation
@preconcurrency import AVFoundation
import Foundation

// MARK: - AVAssetTimecodeSource

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
struct AVAssetTimecodeSource {
var asset: AVAsset
var attribute: RangeAttribute
let asset: AVAsset
let attribute: RangeAttribute
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
Expand Down Expand Up @@ -111,8 +111,8 @@ extension AsyncTimecodeSourceValue {

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
struct AVAssetRichTimecodeSource {
var asset: AVAsset
var attribute: RangeAttribute
let asset: AVAsset
let attribute: RangeAttribute
}

@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
// MARK: - TimecodeSource

@available(macOS 10.7, iOS 4.0, tvOS 9.0, watchOS 6.0, *)
extension CMTime: _TimecodeSource {
extension CMTime: /* @retroactive */ _TimecodeSource, @unchecked Sendable {
func set(timecode: inout Timecode) throws {
try timecode._setTimecode(exactly: self)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,45 +43,46 @@ extension TimecodeFrameRate {
/// frame number will differ. They will then both reach `01:00:01:00` at exactly the same time, and so on.
///
/// - note: These are intended for internal logic and not for end-user user interface.
public static var table: [CompatibleGroup: [TimecodeFrameRate]] =
[
.ntscColor: [
.fps23_976,
.fps24_98,
.fps29_97,
.fps47_952,
.fps59_94,
.fps95_904,
.fps119_88
],

.ntscDrop: [
.fps29_97d,
.fps59_94d,
.fps119_88d
],

.whole: [
.fps24,
.fps25,
.fps30,
.fps48,
.fps50,
.fps60,
.fps96,
.fps100,
.fps120
],

.ntscColorWallTime: [
.fps30d,
.fps60d,
.fps120d
]
public static let table: [CompatibleGroup: [TimecodeFrameRate]] = [
.ntscColor: [
.fps23_976,
.fps24_98,
.fps29_97,
.fps47_952,
.fps59_94,
.fps95_904,
.fps119_88
],

.ntscDrop: [
.fps29_97d,
.fps59_94d,
.fps119_88d
],

.whole: [
.fps24,
.fps25,
.fps30,
.fps48,
.fps50,
.fps60,
.fps96,
.fps100,
.fps120
],

.ntscColorWallTime: [
.fps30d,
.fps60d,
.fps120d
]
]
}
}

extension TimecodeFrameRate.CompatibleGroup: Sendable { }

extension TimecodeFrameRate.CompatibleGroup: CustomStringConvertible {
public var description: String {
stringValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import TimecodeKit
@_documentation(visibility: internal)
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
extension Timecode {
@_disfavoredOverload
@MainActor @_disfavoredOverload
@available(
*,
deprecated,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,11 @@ extension TimecodeField {
private func handleKeyPress(key: KeyEquivalent) -> KeyPress.Result {
switch key {
case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9":
var priorNonVirginDigitCount = isVirgin ? 0 : value.numberOfDigits

let proposedValue: Int?

defer { setIsVirgin(false) }
if isVirgin {
proposedValue = Int("\(key.character)")
defer { setIsVirgin(false) }
} else {
proposedValue = Int("\(value)\(key.character)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import TimecodeKit
@_documentation(visibility: internal)
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
struct TimecodeFieldHighlightStyleKey: EnvironmentKey {
public static var defaultValue: Color? = .accentColor
public static let defaultValue: Color? = .accentColor
}

@_documentation(visibility: internal)
Expand All @@ -38,7 +38,7 @@ extension EnvironmentValues {
@available(watchOS, unavailable)
@available(tvOS, unavailable)
struct TimecodeFieldInputStyleKey: EnvironmentKey {
public static var defaultValue: TimecodeField.InputStyle = .autoAdvance
public static let defaultValue: TimecodeField.InputStyle = .autoAdvance
}

@_documentation(visibility: internal)
Expand All @@ -61,7 +61,7 @@ extension EnvironmentValues {
@available(watchOS, unavailable)
@available(tvOS, unavailable)
struct TimecodeFieldInputWrappingKey: EnvironmentKey {
public static var defaultValue: TimecodeField.InputWrapping = .wrap
public static let defaultValue: TimecodeField.InputWrapping = .wrap
}

@_documentation(visibility: internal)
Expand All @@ -84,7 +84,7 @@ extension EnvironmentValues {
@available(watchOS, unavailable)
@available(tvOS, unavailable)
struct TimecodeFieldReturnActionKey: EnvironmentKey {
public static var defaultValue: TimecodeField.FieldAction? = nil
public static let defaultValue: TimecodeField.FieldAction? = nil
}

@_documentation(visibility: internal)
Expand All @@ -107,7 +107,7 @@ extension EnvironmentValues {
@available(watchOS, unavailable)
@available(tvOS, unavailable)
struct TimecodeFieldEscapeActionKey: EnvironmentKey {
public static var defaultValue: TimecodeField.FieldAction? = nil
public static let defaultValue: TimecodeField.FieldAction? = nil
}

@_documentation(visibility: internal)
Expand All @@ -128,7 +128,7 @@ extension EnvironmentValues {
@_documentation(visibility: internal)
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
struct TimecodeFormatKey: EnvironmentKey {
public static var defaultValue: Timecode.StringFormat = .default()
public static let defaultValue: Timecode.StringFormat = .default()
}

@_documentation(visibility: internal)
Expand All @@ -150,7 +150,7 @@ extension EnvironmentValues {
@_documentation(visibility: internal)
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
struct TimecodeSeparatorStyleKey: EnvironmentKey {
public static var defaultValue: Color? = nil
public static let defaultValue: Color? = nil
}

@_documentation(visibility: internal)
Expand All @@ -172,7 +172,7 @@ extension EnvironmentValues {
@_documentation(visibility: internal)
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
struct TimecodeValidationStyleKey: EnvironmentKey {
public static var defaultValue: Color? = .red
public static let defaultValue: Color? = .red
}

@_documentation(visibility: internal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ import TimecodeKit
/// > when we want to observe changes to individual `Timecode` properties in SwiftUI. The solution is a custom state
/// > wrapper that forces view updates when any `Timecode` property changes.
@available(macOS 11, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
@propertyWrapper public struct TimecodeState: DynamicProperty {
@MainActor
@propertyWrapper public struct TimecodeState: DynamicProperty, Sendable {
public typealias Value = Timecode

@StateObject private var wrapper: Wrapper
Expand All @@ -71,17 +72,17 @@ import TimecodeKit

// public func update() { }

private class Wrapper: ObservableObject {
private final class Wrapper: ObservableObject {
var timecode: Timecode {
willSet {
// this is tantamount to a custom Equatable implementation
guard timecode.components != newValue.components ||
timecode.properties != newValue.properties
else { return }

DispatchQueue.main.async {
// DispatchQueue.main.async {
self.objectWillChange.send()
}
// }
}
}

Expand Down

0 comments on commit eb9e5dd

Please sign in to comment.