Skip to content

Commit

Permalink
Merge pull request #136 from treastrain/update-to-swift-tools-version…
Browse files Browse the repository at this point in the history
…-6.0

Support Swift 6
  • Loading branch information
treastrain committed Sep 15, 2024
2 parents 81d6f7b + 1670a43 commit 071bd51
Show file tree
Hide file tree
Showing 31 changed files with 90 additions and 84 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ on:
branches: [ tretnfckit-main ]

env:
XCODE_SELECT_PATH: '/Applications/Xcode_15.2.app/Contents/Developer'
XCODE_SELECT_PATH: '/Applications/Xcode_16_Release_Candidate.app/Contents/Developer'

jobs:
show_software_information:
name: Show software information
strategy:
fail-fast: false
matrix:
os: [macos-14, ubuntu-20.04, ubuntu-22.04]
# os: [macos-14, ubuntu-20.04, ubuntu-22.04]
os: [macos-14]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -30,7 +31,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-14, ubuntu-20.04, ubuntu-22.04]
# os: [macos-14, ubuntu-20.04, ubuntu-22.04]
os: [macos-14]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/xcodebuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
TVOS_SIMULATOR_NAME: Apple TV 4K (3rd generation)
WATCHOS_SIMULATOR_NAME: Apple Watch Ultra 2 (49mm)
VISIONOS_SIMULATOR_NAME: Apple Vision Pro
XCODE_SELECT_PATH: '/Applications/Xcode_15.2.app/Contents/Developer'
XCODE_SELECT_PATH: '/Applications/Xcode_16_Release_Candidate.app/Contents/Developer'

jobs:
show_software_information:
Expand Down Expand Up @@ -70,20 +70,22 @@ jobs:
- name: Test the scheme
run: |
case ${{ matrix.platform }} in
'iOS' ) xcodebuild test -scheme ${{ env.SCHEME_NAME }} -destination 'name=${{ env.IOS_SIMULATOR_NAME }}' -resultBundlePath TestResults-${{ matrix.os }}-${{ matrix.platform }} ;;
'iOS' ) xcodebuild test -scheme ${{ env.SCHEME_NAME }} -destination 'name=${{ env.IOS_SIMULATOR_NAME }}' -resultBundlePath TestResults-${{ matrix.os }}-${{ matrix.platform }}.xcresult ;;
'macOS-x86_64' ) xcodebuild test -scheme ${{ env.SCHEME_NAME }} -destination 'platform=macOS,arch=x86_64' -resultBundlePath TestResults-${{ matrix.os }}-${{ matrix.platform }} ;;
'macCatalyst-x86_64' ) xcodebuild test -scheme ${{ env.SCHEME_NAME }} -destination 'platform=macOS,arch=x86_64,variant=Mac Catalyst' -resultBundlePath TestResults-${{ matrix.os }}-${{ matrix.platform }} ;;
'macOS-arm64' ) xcodebuild test -scheme ${{ env.SCHEME_NAME }} -destination 'platform=macOS,arch=arm64' -resultBundlePath TestResults-${{ matrix.os }}-${{ matrix.platform }} ;;
'macCatalyst-arm64' ) xcodebuild test -scheme ${{ env.SCHEME_NAME }} -destination 'platform=macOS,arch=arm64,variant=Mac Catalyst' -resultBundlePath TestResults-${{ matrix.os }}-${{ matrix.platform }} ;;
'tvOS' ) xcodebuild test -scheme ${{ env.SCHEME_NAME }} -destination 'name=${{ env.TVOS_SIMULATOR_NAME }}' -resultBundlePath TestResults-${{ matrix.os }}-${{ matrix.platform }} ;;
'watchOS' ) xcodebuild test -scheme ${{ env.SCHEME_NAME }} -destination 'name=${{ env.WATCHOS_SIMULATOR_NAME }}' -resultBundlePath TestResults-${{ matrix.os }}-${{ matrix.platform }} ;;
'visionOS' ) xcodebuild test -scheme ${{ env.SCHEME_NAME }} -destination 'name=${{ env.VISIONOS_SIMULATOR_NAME }}' -resultBundlePath TestResults-${{ matrix.os }}-${{ matrix.platform }} ;;
'macCatalyst-x86_64' ) xcodebuild test -scheme ${{ env.SCHEME_NAME }} -destination 'platform=macOS,arch=x86_64,variant=Mac Catalyst' -resultBundlePath TestResults-${{ matrix.os }}-${{ matrix.platform }}.xcresult ;;
'macOS-arm64' ) xcodebuild test -scheme ${{ env.SCHEME_NAME }} -destination 'platform=macOS,arch=arm64' -resultBundlePath TestResults-${{ matrix.os }}-${{ matrix.platform }}.xcresult ;;
'macCatalyst-arm64' ) xcodebuild test -scheme ${{ env.SCHEME_NAME }} -destination 'platform=macOS,arch=arm64,variant=Mac Catalyst' -resultBundlePath TestResults-${{ matrix.os }}-${{ matrix.platform }}.xcresult ;;
'tvOS' ) xcodebuild test -scheme ${{ env.SCHEME_NAME }} -destination 'name=${{ env.TVOS_SIMULATOR_NAME }}' -resultBundlePath TestResults-${{ matrix.os }}-${{ matrix.platform }}.xcresult ;;
'watchOS' ) xcodebuild test -scheme ${{ env.SCHEME_NAME }} -destination 'name=${{ env.WATCHOS_SIMULATOR_NAME }}' -resultBundlePath TestResults-${{ matrix.os }}-${{ matrix.platform }}.xcresult ;;
'visionOS' ) xcodebuild test -scheme ${{ env.SCHEME_NAME }} -destination 'name=${{ env.VISIONOS_SIMULATOR_NAME }}' -resultBundlePath TestResults-${{ matrix.os }}-${{ matrix.platform }}.xcresult ;;
esac
- uses: kishikawakatsumi/xcresulttool@v1
with:
path: TestResults-${{ matrix.os }}-${{ matrix.platform }}.xcresult
title: Xcode test results (${{ matrix.os }}, ${{ matrix.platform }})
if: success() || failure()
# if: success() || failure()
# https://x.com/treastrain/status/1835273045059199464
if: false
- name: Upload Xcode DerivedData
if: always()
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/xcodebuild_for_example_app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
env:
SCHEME_NAME: TRETNFCKitExample
IOS_SIMULATOR_NAME: iPhone 15 Pro
XCODE_SELECT_PATH: '/Applications/Xcode_15.2.app/Contents/Developer'
XCODE_SELECT_PATH: '/Applications/Xcode_16_Release_Candidate.app/Contents/Developer'

jobs:
show_software_information:
Expand Down
43 changes: 17 additions & 26 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0

import PackageDescription

let packageName = "TRETNFCKit"

extension SwiftSetting {
static let forwardTrailingClosures: Self = .enableUpcomingFeature("ForwardTrailingClosures")
static let strictConcurrency: Self = .enableUpcomingFeature("StrictConcurrency")
static let existentialAny: Self = .enableUpcomingFeature("ExistentialAny")
static let bareSlashRegexLiterals: Self = .enableUpcomingFeature("BareSlashRegexLiterals")
static let conciseMagicFile: Self = .enableUpcomingFeature("ConciseMagicFile")
static let importObjcForwardDeclarations: Self = .enableUpcomingFeature("ImportObjcForwardDeclarations")
static let disableOutwardActorInference: Self = .enableUpcomingFeature("DisableOutwardActorInference")
static let existentialAny: Self = .enableUpcomingFeature("ExistentialAny") // SE-0335, Swift 5.6, SwiftPM 5.8+
static let internalImportsByDefault: Self = .enableUpcomingFeature("InternalImportsByDefault") // SE-0409, Swift 6.0, SwiftPM 6.0+
}

let swiftSettings: [SwiftSetting] = [
.forwardTrailingClosures,
.strictConcurrency,
.existentialAny,
.bareSlashRegexLiterals,
.conciseMagicFile,
.importObjcForwardDeclarations,
.disableOutwardActorInference,
.internalImportsByDefault,
]

var products: [Product] = []
var targets: [Target] = []

@discardableResult
func add(moduleName: String, dependencies: [Target.Dependency] = [], includesTest: Bool) -> Target.Dependency {
@MainActor func add(moduleName: String, dependencies: [Target.Dependency] = [], includesTest: Bool, swiftLanguageMode: SwiftLanguageMode) -> Target.Dependency {
let targetName = "\(packageName)_\(moduleName)"
let target = Target.Dependency(stringLiteral: targetName)
products.append(
.library(name: targetName, targets: [targetName])
)
let swiftSettings = swiftSettings + [.swiftLanguageMode(swiftLanguageMode)]
targets.append(
.target(name: targetName, dependencies: dependencies, path: "Sources/\(moduleName)", swiftSettings: swiftSettings)
)
Expand All @@ -46,21 +37,21 @@ func add(moduleName: String, dependencies: [Target.Dependency] = [], includesTes
}

// MARK: - Modules - Tools for DEBUG
let assertServices = add(moduleName: "AssertServices", includesTest: false)
let infoPListChecker = add(moduleName: "InfoPListChecker", includesTest: false)
let assertServices = add(moduleName: "AssertServices", includesTest: false, swiftLanguageMode: .v6)
let infoPListChecker = add(moduleName: "InfoPListChecker", includesTest: false, swiftLanguageMode: .v6)

// MARK: - Modules - Primary
let async = add(moduleName: "Async", includesTest: false)
let core = add(moduleName: "Core", dependencies: [assertServices, infoPListChecker], includesTest: true)
let nativeTag = add(moduleName: "NativeTag", dependencies: [core], includesTest: true)
add(moduleName: "NDEFMessage", dependencies: [core], includesTest: true)
add(moduleName: "NDEFTag", dependencies: [core], includesTest: true)
let async = add(moduleName: "Async", includesTest: false, swiftLanguageMode: .v5)
let core = add(moduleName: "Core", dependencies: [assertServices, infoPListChecker], includesTest: true, swiftLanguageMode: .v6)
let nativeTag = add(moduleName: "NativeTag", dependencies: [core], includesTest: true, swiftLanguageMode: .v6)
add(moduleName: "NDEFMessage", dependencies: [core], includesTest: true, swiftLanguageMode: .v5)
add(moduleName: "NDEFTag", dependencies: [core], includesTest: true, swiftLanguageMode: .v5)

// MARK: - Modules - Secondary
add(moduleName: "FeliCa", dependencies: [nativeTag], includesTest: true)
add(moduleName: "ISO7816", dependencies: [nativeTag], includesTest: true)
add(moduleName: "ISO15693", dependencies: [nativeTag], includesTest: true)
add(moduleName: "MiFare", dependencies: [nativeTag], includesTest: true)
add(moduleName: "FeliCa", dependencies: [nativeTag], includesTest: true, swiftLanguageMode: .v5)
add(moduleName: "ISO7816", dependencies: [nativeTag], includesTest: true, swiftLanguageMode: .v5)
add(moduleName: "ISO15693", dependencies: [nativeTag], includesTest: true, swiftLanguageMode: .v5)
add(moduleName: "MiFare", dependencies: [nativeTag], includesTest: true, swiftLanguageMode: .v5)

// MARK: - Package
products.append(
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ A wrapper for Core NFC and a useful helper when using NFC, leveraging Swift feat
[![GitHub Stars](https://img.shields.io/github/stars/treastrain/TRETJapanNFCReader)](https://github.com/treastrain/TRETJapanNFCReader/stargazers) \
![Platform: iOS & iPadOS|macOS|tvOS|watchOS|visionOS](https://img.shields.io/badge/Platform-iOS%20%26%20iPadOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS%20%7C%20visionOS-lightgrey.svg)
![SwiftUI compatible](https://img.shields.io/badge/SwiftUI-compatible-brightgreen.svg) \
![Swift: 5.9](https://img.shields.io/badge/Swift-5.9-orange.svg)
![Swift: 6.0](https://img.shields.io/badge/Swift-6.0-orange.svg)
[![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager) \
[![Twitter: @treastrain](https://img.shields.io/twitter/follow/treastrain?label=%40treastrain&style=social)](https://twitter.com/treastrain) \
[![X (formerly Twitter): @treastrain](https://img.shields.io/twitter/follow/treastrain?label=%40treastrain&style=social)](https://twitter.com/treastrain) \
[![Swift Build & Test](https://github.com/treastrain/TRETJapanNFCReader/actions/workflows/swift.yml/badge.svg?branch=tretnfckit-main)](https://github.com/treastrain/TRETJapanNFCReader/actions/workflows/swift.yml)
[![Xcode Build & Test](https://github.com/treastrain/TRETJapanNFCReader/actions/workflows/xcodebuild.yml/badge.svg?branch=tretnfckit-main)](https://github.com/treastrain/TRETJapanNFCReader/actions/workflows/xcodebuild.yml)
[![Example App Build](https://github.com/treastrain/TRETJapanNFCReader/actions/workflows/xcodebuild_for_example_app.yml/badge.svg?branch=tretnfckit-main)](https://github.com/treastrain/TRETJapanNFCReader/actions/workflows/xcodebuild_for_example_app.yml)
Expand Down
4 changes: 2 additions & 2 deletions Sources/AssertServices/AssertServices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ package func assertionFailure(_ message: @autoclosure () -> String = String(), f
}

struct AssertServices {
static var assertionFailureHandler: (String, StaticString, UInt) -> () = assertionFailureDefaultHandler
static let assertionFailureDefaultHandler = { Swift.assertionFailure($0, file: $1, line: $2) }
nonisolated(unsafe) static var assertionFailureHandler: (String, StaticString, UInt) -> () = assertionFailureDefaultHandler
nonisolated(unsafe) static let assertionFailureDefaultHandler = { Swift.assertionFailure($0, file: $1, line: $2) }
}
6 changes: 3 additions & 3 deletions Sources/Core/NFCNDEFReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
//

#if canImport(CoreNFC)
@preconcurrency import protocol CoreNFC.NFCNDEFTag
public import protocol CoreNFC.NFCNDEFTag

public actor NFCNDEFReader: Actor {
private let session: Session
private nonisolated(unsafe) let session: Session
public nonisolated let taskPriority: TaskPriority?

public init(delegate: any Delegate & Actor, taskPriority: TaskPriority?, invalidateAfterFirstRead: Bool) {
Expand All @@ -21,7 +21,7 @@ public actor NFCNDEFReader: Actor {
session.restartPolling()
}

public func connect(to tag: any NFCNDEFTag) async throws {
public func connect(to tag: sending any NFCNDEFTag) async throws {
try await session.connect(to: tag)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Core/NFCTagReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
//

#if canImport(CoreNFC)
@preconcurrency import enum CoreNFC.NFCTag
public import enum CoreNFC.NFCTag

public actor NFCTagReader: Actor {
private let session: Session
private nonisolated(unsafe) let session: Session
public nonisolated let taskPriority: TaskPriority?

public init?(pollingOption: Session.PollingOption, delegate: any Delegate & Actor, taskPriority: TaskPriority? = nil) {
Expand All @@ -26,7 +26,7 @@ public actor NFCTagReader: Actor {

public var connectedTag: NFCTag? { session.connectedTag }

public func connect(to tag: NFCTag) async throws {
public func connect(to tag: sending NFCTag) async throws {
try await session.connect(to: tag)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/NFCVASReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

#if canImport(CoreNFC)
@preconcurrency import class CoreNFC.NFCVASCommandConfiguration
public import class CoreNFC.NFCVASCommandConfiguration

public actor NFCVASReader: Actor {
private let session: Session
Expand Down
2 changes: 1 addition & 1 deletion Sources/FeliCa/FeliCaTagReaderViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#if canImport(SwiftUI) && canImport(CoreNFC)
import Combine
import SwiftUI
public import SwiftUI

public struct FeliCaTagReaderViewModifier: @unchecked Sendable {
private var isPresented: Binding<Bool>
Expand Down
2 changes: 1 addition & 1 deletion Sources/ISO15693/ISO15693TagReaderViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#if canImport(SwiftUI) && canImport(CoreNFC)
import Combine
import SwiftUI
public import SwiftUI

public struct ISO15693TagReaderViewModifier: @unchecked Sendable {
private var isPresented: Binding<Bool>
Expand Down
2 changes: 1 addition & 1 deletion Sources/ISO7816/ISO7816TagReaderViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#if canImport(SwiftUI) && canImport(CoreNFC)
import Combine
import SwiftUI
public import SwiftUI

public struct ISO7816TagReaderViewModifier: @unchecked Sendable {
private var isPresented: Binding<Bool>
Expand Down
2 changes: 1 addition & 1 deletion Sources/InfoPListChecker/InfoPListChecker+Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by treastrain on 2022/11/27.
//

import Foundation
public import Foundation

extension InfoPListChecker {
public enum Error: LocalizedError {
Expand Down
4 changes: 2 additions & 2 deletions Sources/InfoPListChecker/InfoPListChecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// Created by treastrain on 2022/11/26.
//

import Foundation
public import Foundation

public struct InfoPListChecker {
public struct InfoPListChecker: Sendable {
public static let main: Self = .init(bundle: .main)

public init(bundle: Bundle) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/MiFare/MiFareTagReaderViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#if canImport(SwiftUI) && canImport(CoreNFC)
import Combine
import SwiftUI
public import SwiftUI

public struct MiFareTagReaderViewModifier: @unchecked Sendable {
private var isPresented: Binding<Bool>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

#if canImport(CoreNFC)
@preconcurrency import class CoreNFC.NFCNDEFMessage
public import class CoreNFC.NFCNDEFMessage
#endif

#if canImport(ObjectiveC)
Expand Down
2 changes: 1 addition & 1 deletion Sources/NDEFMessage/NFCNDEFMessageReaderViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#if canImport(SwiftUI) && canImport(CoreNFC)
import Combine
import SwiftUI
public import SwiftUI

public struct NFCNDEFMessageReaderViewModifier: @unchecked Sendable {
private var isPresented: Binding<Bool>
Expand Down
2 changes: 1 addition & 1 deletion Sources/NDEFTag/NFCNDEFTagReaderCallbackHandleObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

#if canImport(CoreNFC)
@preconcurrency import protocol CoreNFC.NFCNDEFTag
public import protocol CoreNFC.NFCNDEFTag
#endif

#if canImport(ObjectiveC)
Expand Down
2 changes: 1 addition & 1 deletion Sources/NDEFTag/NFCNDEFTagReaderViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#if canImport(SwiftUI) && canImport(CoreNFC)
import Combine
import SwiftUI
public import SwiftUI

public struct NFCNDEFTagReaderViewModifier: @unchecked Sendable {
private var isPresented: Binding<Bool>
Expand Down
17 changes: 14 additions & 3 deletions Sources/NativeTag/NFCNativeTagReaderCallBackHandleObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

#if canImport(CoreNFC)
@preconcurrency import enum CoreNFC.NFCTag
public import enum CoreNFC.NFCTag
#endif

#if canImport(ObjectiveC)
Expand Down Expand Up @@ -48,21 +48,32 @@ extension NFCNativeTagReaderCallBackHandleObject: NativeTag.Reader.Delegate {
}

public nonisolated func tagReaderSession(_ session: TagType.Reader.Session, didDetect tags: TagType.ReaderDetectObject) {
let tags = NFCTags(tags: tags)
Task(priority: taskPriority) {
await didDetect(tags: tags)
}
}
}

extension NFCNativeTagReaderCallBackHandleObject {
struct NFCTags: Sendable {
nonisolated(unsafe) let base: TagType.ReaderDetectObject

init(tags: TagType.ReaderDetectObject) {
self.base = tags
}
}
}

extension NFCNativeTagReaderCallBackHandleObject {
func didBecomeActive() async {
await didBecomeActiveHandler(reader as! TagType.Reader.AfterBeginProtocol)
}

func didDetect(tags: TagType.ReaderDetectObject) async {
func didDetect(tags: NFCTags) async {
let result: TagType.DetectResult
do {
result = try await didDetectHandler(reader as! TagType.ReaderProtocol, tags)
result = try await didDetectHandler(reader as! TagType.ReaderProtocol, tags.base)
} catch {
result = .failure(with: error)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/NativeTag/NFCNativeTagReaderProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public protocol NFCNativeTagReaderProtocol: NFCReaderAfterBeginProtocol {
#if canImport(CoreNFC)
func connect(to tag: NFCTag) async throws
func connect(to tag: sending NFCTag) async throws
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/NativeTag/NFCNativeTagReaderViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#if canImport(SwiftUI) && canImport(CoreNFC)
import Combine
import SwiftUI
public import SwiftUI

public struct NFCNativeTagReaderViewModifier: @unchecked Sendable {
private var isPresented: Binding<Bool>
Expand Down
Loading

0 comments on commit 071bd51

Please sign in to comment.