Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure access to PDFDocument is always concurrency safe #58

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SpeziOnboarding/ConsentConstraint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
///
/// - Parameters:
/// - consent: The exported consent form represented as `ConsentDocumentExport` that should be added.
func store(consent: ConsentDocumentExport) async throws
func store(consent: consuming sending ConsentDocumentExport) async throws

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iPadOS / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iPadOS / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iPadOS / Test using xcodebuild or run fastlane

cannot find type 'sending' in scope

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iPadOS / Test using xcodebuild or run fastlane

noncopyable parameter must specify its ownership

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Debug, SpeziOnboarding-iOS.xcresult, SpeziOnboarding-iOS.xcresult) / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Debug, SpeziOnboarding-iOS.xcresult, SpeziOnboarding-iOS.xcresult) / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Debug, SpeziOnboarding-iOS.xcresult, SpeziOnboarding-iOS.xcresult) / Test using xcodebuild or run fastlane

cannot find type 'sending' in scope

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Debug, SpeziOnboarding-iOS.xcresult, SpeziOnboarding-iOS.xcresult) / Test using xcodebuild or run fastlane

noncopyable parameter must specify its ownership

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Release, SpeziOnboarding-iOS-Release.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Release, SpeziOnboarding-iOS-Release.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Debug, SpeziOnboarding-macOS.xcresult, SpeziOnboarding-macOS.... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Debug, SpeziOnboarding-macOS.xcresult, SpeziOnboarding-macOS.... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Debug, SpeziOnboarding-macOS.xcresult, SpeziOnboarding-macOS.... / Test using xcodebuild or run fastlane

cannot find type 'sending' in scope

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Debug, SpeziOnboarding-macOS.xcresult, SpeziOnboarding-macOS.... / Test using xcodebuild or run fastlane

noncopyable parameter must specify its ownership

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Release, SpeziOnboarding-macOS-Release.xcresult, SpeziOnboard... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Release, SpeziOnboarding-macOS-Release.xcresult, SpeziOnboard... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

cannot find type 'sending' in scope

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

noncopyable parameter must specify its ownership

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS (Release, TestApp-iOS-Release.xcresult, TestApp-iOS-Release.xcresult) / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS (Release, TestApp-iOS-Release.xcresult, TestApp-iOS-Release.xcresult) / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Debug, TestApp-visionOS.xcresult, TestApp-visionOS.xcresult) / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Debug, TestApp-visionOS.xcresult, TestApp-visionOS.xcresult) / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Debug, TestApp-visionOS.xcresult, TestApp-visionOS.xcresult) / Test using xcodebuild or run fastlane

cannot find type 'sending' in scope

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Debug, TestApp-visionOS.xcresult, TestApp-visionOS.xcresult) / Test using xcodebuild or run fastlane

noncopyable parameter must specify its ownership

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Release, TestApp-visionOS-Release.xcresult, TestApp-visionOS-Re... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 20 in Sources/SpeziOnboarding/ConsentConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Release, TestApp-visionOS-Release.xcresult, TestApp-visionOS-Re... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'
}
41 changes: 26 additions & 15 deletions Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,51 @@

import PDFKit


/// A type representing an exported `ConsentDocument`. It holds the exported `PDFDocument` and the corresponding document identifier String.
public actor ConsentDocumentExport {
public struct ConsentDocumentExport: ~Copyable {
/// Provides default values for fields related to the `ConsentDocumentExport`.
public enum Defaults {
/// Default value for a document identifier.
///
/// This identifier will be used as default value if no identifier is provided.
public static let documentIdentifier = "ConsentDocument"
}

private var cachedPDF: PDFDocument
private let cachedPDF: PDFDocument

/// An unique identifier for the exported `ConsentDocument`.
///
/// Corresponds to the identifier which was passed when creating the `ConsentDocument` using an `OnboardingConsentView`.
public let documentIdentifier: String
/// The `PDFDocument` exported from a `ConsentDocument`.
/// This property is asynchronous and accesing it potentially triggers the export of the PDF from the underlying `ConsentDocument`,
/// if the `ConsentDocument` has not been previously exported or the `PDFDocument` was not cached.
/// For now, we always require a PDF to be cached to create a ConsentDocumentExport. In the future, we might change this to lazy-PDF loading.
public var pdf: PDFDocument {
get async {
cachedPDF
}
}



/// Creates a `ConsentDocumentExport`, which holds an exported PDF and the corresponding document identifier string.
/// - Parameters:
/// - documentIdentfier: A unique String identifying the exported `ConsentDocument`.
/// - documentIdentifier: A unique String identifying the exported `ConsentDocument`.
/// - cachedPDF: A `PDFDocument` exported from a `ConsentDocument`.
init(
documentIdentifier: String,
cachedPDF: PDFDocument
cachedPDF: sending PDFDocument

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iPadOS / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iPadOS / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iPadOS / Test using xcodebuild or run fastlane

cannot find type 'sending' in scope

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Debug, SpeziOnboarding-iOS.xcresult, SpeziOnboarding-iOS.xcresult) / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Debug, SpeziOnboarding-iOS.xcresult, SpeziOnboarding-iOS.xcresult) / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Debug, SpeziOnboarding-iOS.xcresult, SpeziOnboarding-iOS.xcresult) / Test using xcodebuild or run fastlane

cannot find type 'sending' in scope

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Release, SpeziOnboarding-iOS-Release.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Release, SpeziOnboarding-iOS-Release.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Debug, SpeziOnboarding-macOS.xcresult, SpeziOnboarding-macOS.... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Debug, SpeziOnboarding-macOS.xcresult, SpeziOnboarding-macOS.... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Debug, SpeziOnboarding-macOS.xcresult, SpeziOnboarding-macOS.... / Test using xcodebuild or run fastlane

cannot find type 'sending' in scope

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Release, SpeziOnboarding-macOS-Release.xcresult, SpeziOnboard... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Release, SpeziOnboarding-macOS-Release.xcresult, SpeziOnboard... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

cannot find type 'sending' in scope

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS (Release, TestApp-iOS-Release.xcresult, TestApp-iOS-Release.xcresult) / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS (Release, TestApp-iOS-Release.xcresult, TestApp-iOS-Release.xcresult) / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Debug, TestApp-visionOS.xcresult, TestApp-visionOS.xcresult) / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Debug, TestApp-visionOS.xcresult, TestApp-visionOS.xcresult) / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Debug, TestApp-visionOS.xcresult, TestApp-visionOS.xcresult) / Test using xcodebuild or run fastlane

cannot find type 'sending' in scope

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Release, TestApp-visionOS-Release.xcresult, TestApp-visionOS-Re... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 36 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Release, TestApp-visionOS-Release.xcresult, TestApp-visionOS-Re... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'
) {
self.documentIdentifier = documentIdentifier
self.cachedPDF = cachedPDF
}

/// Consume the exported `PDFDocument` from a `ConsentDocument`.
///
/// This method consumes the `ConsentDocumentExport` by retrieving the exported `PDFDocument`.
///
/// This property is asynchronous and accessing it potentially triggers the export of the PDF from the underlying `ConsentDocument`,
/// if the `ConsentDocument` has not been previously exported or the `PDFDocument` was not cached.
///
/// - Note: For now, we always require a PDF to be cached to create a ConsentDocumentExport. In the future, we might change this to lazy-PDF loading.
public consuming func consumePDF() async -> sending PDFDocument {

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iPadOS / Test using xcodebuild or run fastlane

consecutive declarations on a line must be separated by ';'

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iPadOS / Test using xcodebuild or run fastlane

expected declaration

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iPadOS / Test using xcodebuild or run fastlane

cannot find type 'sending' in scope

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Debug, SpeziOnboarding-iOS.xcresult, SpeziOnboarding-iOS.xcresult) / Test using xcodebuild or run fastlane

consecutive declarations on a line must be separated by ';'

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Debug, SpeziOnboarding-iOS.xcresult, SpeziOnboarding-iOS.xcresult) / Test using xcodebuild or run fastlane

expected declaration

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Debug, SpeziOnboarding-iOS.xcresult, SpeziOnboarding-iOS.xcresult) / Test using xcodebuild or run fastlane

cannot find type 'sending' in scope

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Release, SpeziOnboarding-iOS-Release.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

consecutive declarations on a line must be separated by ';'

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Release, SpeziOnboarding-iOS-Release.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

expected declaration

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Debug, SpeziOnboarding-macOS.xcresult, SpeziOnboarding-macOS.... / Test using xcodebuild or run fastlane

consecutive declarations on a line must be separated by ';'

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Debug, SpeziOnboarding-macOS.xcresult, SpeziOnboarding-macOS.... / Test using xcodebuild or run fastlane

expected declaration

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Debug, SpeziOnboarding-macOS.xcresult, SpeziOnboarding-macOS.... / Test using xcodebuild or run fastlane

cannot find type 'sending' in scope

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Release, SpeziOnboarding-macOS-Release.xcresult, SpeziOnboard... / Test using xcodebuild or run fastlane

consecutive declarations on a line must be separated by ';'

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Release, SpeziOnboarding-macOS-Release.xcresult, SpeziOnboard... / Test using xcodebuild or run fastlane

expected declaration

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

consecutive declarations on a line must be separated by ';'

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

expected declaration

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package visionOS (Debug, SpeziOnboarding-visionOS.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

cannot find type 'sending' in scope

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS (Release, TestApp-iOS-Release.xcresult, TestApp-iOS-Release.xcresult) / Test using xcodebuild or run fastlane

consecutive declarations on a line must be separated by ';'

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS (Release, TestApp-iOS-Release.xcresult, TestApp-iOS-Release.xcresult) / Test using xcodebuild or run fastlane

expected declaration

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Debug, TestApp-visionOS.xcresult, TestApp-visionOS.xcresult) / Test using xcodebuild or run fastlane

consecutive declarations on a line must be separated by ';'

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Debug, TestApp-visionOS.xcresult, TestApp-visionOS.xcresult) / Test using xcodebuild or run fastlane

expected declaration

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Debug, TestApp-visionOS.xcresult, TestApp-visionOS.xcresult) / Test using xcodebuild or run fastlane

cannot find type 'sending' in scope

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Release, TestApp-visionOS-Release.xcresult, TestApp-visionOS-Re... / Test using xcodebuild or run fastlane

consecutive declarations on a line must be separated by ';'

Check failure on line 50 in Sources/SpeziOnboarding/ConsentView/ConsentDocumentExport.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Release, TestApp-visionOS-Release.xcresult, TestApp-visionOS-Re... / Test using xcodebuild or run fastlane

expected declaration
// Something the compiler doesn't realize here is that we can send the `PDFDocument` because it is located in a non-Sendable, non-Copyable
// type and accessing it will consume the enclosing type. Therefore, the PDFDocument instance can only be accessed once (even in async method)
// and that is fully checked at compile time by the compiler :rocket:
// See similar discussion: https://forums.swift.org/t/swift-6-consume-optional-noncopyable-property-and-transfer-sending-it-out/72414/3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the context!

nonisolated(unsafe) let cachedPDF = cachedPDF
return cachedPDF
}
}
2 changes: 1 addition & 1 deletion Sources/SpeziOnboarding/OnboardingConstraint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
Please use `ConsentConstraint.store(consent: PDFDocument, identifier: String)` instead.
"""
)
func store(consent: PDFDocument) async
func store(consent: sending PDFDocument) async

Check failure on line 36 in Sources/SpeziOnboarding/OnboardingConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Release, SpeziOnboarding-iOS-Release.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 36 in Sources/SpeziOnboarding/OnboardingConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Release, SpeziOnboarding-iOS-Release.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 36 in Sources/SpeziOnboarding/OnboardingConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Release, SpeziOnboarding-macOS-Release.xcresult, SpeziOnboard... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 36 in Sources/SpeziOnboarding/OnboardingConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Release, SpeziOnboarding-macOS-Release.xcresult, SpeziOnboard... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 36 in Sources/SpeziOnboarding/OnboardingConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS (Release, TestApp-iOS-Release.xcresult, TestApp-iOS-Release.xcresult) / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 36 in Sources/SpeziOnboarding/OnboardingConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS (Release, TestApp-iOS-Release.xcresult, TestApp-iOS-Release.xcresult) / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 36 in Sources/SpeziOnboarding/OnboardingConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Release, TestApp-visionOS-Release.xcresult, TestApp-visionOS-Re... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 36 in Sources/SpeziOnboarding/OnboardingConstraint.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Release, TestApp-visionOS-Release.xcresult, TestApp-visionOS-Re... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'
}
24 changes: 21 additions & 3 deletions Sources/SpeziOnboarding/OnboardingDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import SwiftUI


private protocol DeprecationSuppression {
func storeInLegacyConstraint(for standard: any Standard, _ consent: sending PDFDocument) async

Check failure on line 15 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Release, SpeziOnboarding-iOS-Release.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 15 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package iOS (Release, SpeziOnboarding-iOS-Release.xcresult, SpeziOnboarding-... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 15 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Release, SpeziOnboarding-macOS-Release.xcresult, SpeziOnboard... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 15 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test Swift Package macOS (Release, SpeziOnboarding-macOS-Release.xcresult, SpeziOnboard... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 15 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS (Release, TestApp-iOS-Release.xcresult, TestApp-iOS-Release.xcresult) / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 15 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests iOS (Release, TestApp-iOS-Release.xcresult, TestApp-iOS-Release.xcresult) / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'

Check failure on line 15 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Release, TestApp-visionOS-Release.xcresult, TestApp-visionOS-Re... / Test using xcodebuild or run fastlane

expected ',' separator

Check failure on line 15 in Sources/SpeziOnboarding/OnboardingDataSource.swift

View workflow job for this annotation

GitHub Actions / Build and Test UI Tests visionOS (Release, TestApp-visionOS-Release.xcresult, TestApp-visionOS-Re... / Test using xcodebuild or run fastlane

unnamed parameters must be written with the empty name '_'
}


/// Configuration for the Spezi Onboarding module.
///
/// Make sure that your standard in your Spezi Application conforms to the ``OnboardingConstraint``
Expand All @@ -33,13 +38,14 @@
/// }
/// }
/// ```
public class OnboardingDataSource: Module, EnvironmentAccessible {
public final class OnboardingDataSource: Module, EnvironmentAccessible, @unchecked Sendable {
@StandardActor var standard: any Standard


public init() { }


@available(*, deprecated, message: "Propagate deprecation warning")
public func configure() {
guard standard is any OnboardingConstraint || standard is any ConsentConstraint else {
fatalError("A \(type(of: standard).self) must conform to `ConsentConstraint` to process signed consent documents.")
Expand All @@ -49,11 +55,23 @@
/// Adds a new exported consent form represented as `PDFDocument` to the ``OnboardingDataSource``.
///
/// - Parameter consent: The exported consent form represented as `ConsentDocumentExport` that should be added.
public func store(_ consent: PDFDocument, identifier: String = ConsentDocumentExport.Defaults.documentIdentifier) async throws {
public func store(_ consent: sending PDFDocument, identifier: String = ConsentDocumentExport.Defaults.documentIdentifier) async throws {
if let consentConstraint = standard as? any ConsentConstraint {
let consentDocumentExport = ConsentDocumentExport(documentIdentifier: identifier, cachedPDF: consent)
try await consentConstraint.store(consent: consentDocumentExport)
} else if let onboardingConstraint = standard as? any OnboardingConstraint {
} else {
// By down-casting to the protocol we avoid "seeing" the deprecation warning, allowing us to hide it from the compiler.
// We need to call the deprecated symbols for backwards-compatibility.
await (self as DeprecationSuppression).storeInLegacyConstraint(for: standard, consent)
}
}
}


extension OnboardingDataSource: DeprecationSuppression {
@available(*, deprecated, message: "Suppress deprecation warning.")
func storeInLegacyConstraint(for standard: any Standard, _ consent: sending PDFDocument) async {
if let onboardingConstraint = standard as? any OnboardingConstraint {
await onboardingConstraint.store(consent: consent)
} else {
fatalError("A \(type(of: standard).self) must conform to `ConsentConstraint` to process signed consent documents.")
Expand Down
40 changes: 22 additions & 18 deletions Tests/UITests/TestApp/ExampleStandard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,28 @@ actor ExampleStandard: Standard, EnvironmentAccessible {

extension ExampleStandard: ConsentConstraint {
// Example of an async function using MainActor and Task
func store(consent: ConsentDocumentExport) async throws {
func store(consent: consuming sending ConsentDocumentExport) async throws {
// Extract data outside of the MainActor.run block
let documentIdentifier = await consent.documentIdentifier
let pdf = await consent.pdf
let documentIdentifier = consent.documentIdentifier
let pdf = await consent.consumePDF()

// Perform operations on the main actor
try await MainActor.run {
if documentIdentifier == DocumentIdentifiers.first {
self.firstConsentData = pdf
} else if documentIdentifier == DocumentIdentifiers.second {
self.secondConsentData = pdf
} else {
throw ConsentStoreError.invalidIdentifier("Invalid Identifier \(documentIdentifier)")
}
}

try await self.store(document: pdf, for: documentIdentifier)

try? await Task.sleep(for: .seconds(0.5))
}


@MainActor
func store(document pdf: sending PDFDocument, for documentIdentifier: String) throws {
if documentIdentifier == DocumentIdentifiers.first {
self.firstConsentData = pdf
} else if documentIdentifier == DocumentIdentifiers.second {
self.secondConsentData = pdf
} else {
throw ConsentStoreError.invalidIdentifier("Invalid Identifier \(documentIdentifier)")
}
}

func resetDocument(identifier: String) async throws {
await MainActor.run {
if identifier == DocumentIdentifiers.first {
Expand All @@ -49,12 +52,13 @@ extension ExampleStandard: ConsentConstraint {
}
}
}


@MainActor
func loadConsentDocument(identifier: String) async throws -> PDFDocument? {
if identifier == DocumentIdentifiers.first {
return await self.firstConsentData
return self.firstConsentData
} else if identifier == DocumentIdentifiers.second {
return await self.secondConsentData
return self.secondConsentData
}

// In case an invalid identifier is provided, return nil.
Expand Down
Loading