Skip to content

Commit

Permalink
Switch to Swift 6 language mode in NativeTag
Browse files Browse the repository at this point in the history
  • Loading branch information
treastrain committed Sep 14, 2024
1 parent 5766321 commit 2dfbc08
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 13 additions & 2 deletions Sources/NativeTag/NFCNativeTagReaderCallBackHandleObject.swift
Original file line number Diff line number Diff line change
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 Tests/NativeTagTests/NativeTagTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2dfbc08

Please sign in to comment.