From 2dfbc08bd6963c0bf638226103d29de7714115c9 Mon Sep 17 00:00:00 2001 From: treastrain / Tanaka Ryoga Date: Sun, 15 Sep 2024 01:28:45 +0900 Subject: [PATCH] Switch to Swift 6 language mode in NativeTag --- Package.swift | 2 +- .../NFCNativeTagReaderCallBackHandleObject.swift | 15 +++++++++++++-- .../NativeTag/NFCNativeTagReaderProtocol.swift | 2 +- Tests/NativeTagTests/NativeTagTests.swift | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Package.swift b/Package.swift index e5b99f6c..4a905965 100644 --- a/Package.swift +++ b/Package.swift @@ -43,7 +43,7 @@ let infoPListChecker = add(moduleName: "InfoPListChecker", includesTest: false, // MARK: - Modules - Primary 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: .v5) +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) diff --git a/Sources/NativeTag/NFCNativeTagReaderCallBackHandleObject.swift b/Sources/NativeTag/NFCNativeTagReaderCallBackHandleObject.swift index 94325e1b..160df2a6 100644 --- a/Sources/NativeTag/NFCNativeTagReaderCallBackHandleObject.swift +++ b/Sources/NativeTag/NFCNativeTagReaderCallBackHandleObject.swift @@ -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) } diff --git a/Sources/NativeTag/NFCNativeTagReaderProtocol.swift b/Sources/NativeTag/NFCNativeTagReaderProtocol.swift index cf8e0bd7..ffbd340a 100644 --- a/Sources/NativeTag/NFCNativeTagReaderProtocol.swift +++ b/Sources/NativeTag/NFCNativeTagReaderProtocol.swift @@ -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 } diff --git a/Tests/NativeTagTests/NativeTagTests.swift b/Tests/NativeTagTests/NativeTagTests.swift index 060f9c2b..40573c2d 100644 --- a/Tests/NativeTagTests/NativeTagTests.swift +++ b/Tests/NativeTagTests/NativeTagTests.swift @@ -129,7 +129,7 @@ final class NativeTagTests: XCTestCase { let object = tagReaderDelegate as! NFCNativeTagReaderCallBackHandleObject await object.didBecomeActive() - await object.didDetect(tags: []) + await object.didDetect(tags: .init(tags: [])) await fulfillment(of: [didBecomeActiveExpectation, didInvalidateExpectation, didDetectExpectation], timeout: 0.01) #else