Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ca6f212

Browse files
Update OpenAIAsyncImage.swift
1 parent c5c7d0c commit ca6f212

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

‎Sources/openai-async-image-swiftui/OpenAIAsyncImage.swift‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,30 @@ public extension OpenAIAsyncImage where T == OpenAIDefaultLoader{
193193

194194
// MARK: - File private functions -
195195

196+
/// A function that builds the appropriate view for a given `ImageState`.
197+
/// - Parameter state: The current state of the image.
198+
/// - Returns: A SwiftUI view representing the current state of the image.
196199
@ViewBuilder
197-
fileprivate func imageTpl(_ state : ImageState) -> some View{
198-
switch state{
199-
case .loaded(let image) : image.resizable()
200-
case .loadError(let error) : Text(error.localizedDescription)
201-
case .loading : ProgressView()
200+
fileprivate func imageTpl(_ state: ImageState) -> some View {
201+
switch state {
202+
case .loaded(let image):
203+
image.resizable()
204+
case .loadError(let error):
205+
Text(error.localizedDescription)
206+
case .loading:
207+
ProgressView()
202208
}
203209
}
204210

211+
/// Maps an error to a corresponding `AsyncImageErrors` type.
212+
/// - Parameter error: The error to map, which may be `nil`.
213+
/// - Returns: An `AsyncImageErrors` value if the error can be mapped; otherwise, `nil`.
205214
@Sendable
206-
fileprivate func errorMapper(_ error: Error?) -> AsyncImageErrors?{
207-
if error is CancellationError{
215+
fileprivate func errorMapper(_ error: Error?) -> AsyncImageErrors?{
216+
if error is CancellationError{
208217
return .cancellationError
209218
}
210219

220+
// Return nil for other errors
211221
return nil
212222
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /