diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index c2caeab..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitignore b/.gitignore index 330d167..4f20167 100644 --- a/.gitignore +++ b/.gitignore @@ -88,3 +88,4 @@ fastlane/test_output # https://github.com/johnno1962/injectionforxcode iOSInjectionProject/ +.DS_Store diff --git a/README.md b/README.md index c2e16ef..f2fba21 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,7 @@ SwiftUI view that asynchronously loads and displays an OpenAI image from open API -You just type in any your idea and AI will give you an art solution - -DALL-E and DALL-E 2 are deep learning models developed by OpenAI to generate digital images from natural language descriptions, called "prompts" +### Please star the repository if you believe continuing the development of this package is worthwhile. This will help me understand which package deserves more effort. [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fswiftuiux%2Fopenai-async-image-swiftui%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/swiftuiux/openai-async-image-swiftui) @@ -13,10 +11,11 @@ DALL-E and DALL-E 2 are deep learning models developed by OpenAI to generate dig ## Features -- [x] Multiplatform iOS, macOS, watchOS and tvOS -- [x] Customizable in term of SwiftUI Image specs [renderingMode, resizable, antialiased...] -- [x] Customizable in term of the transport layer [Loader] -- [x] Based on interfaces not implementations +- [x] Supports multiple platforms: iOS, macOS, watchOS, and tvOS +- [x] Customizable with SwiftUI Image properties (e.g., `renderingMode`, `resizable`, `antialiased`) +- [x] Configurable transport layer via custom `Loader` +- [x] Designed with interfaces, not implementations +- [x] Fully leverages Swift's new concurrency model ![OpenAI AsyncImage SwiftUI](https://github.com/swiftuiux/openai-async-image-swiftui/blob/main/image/sun_watch.png) diff --git a/Sources/openai-async-image-swiftui/OpenAIAsyncImage.swift b/Sources/openai-async-image-swiftui/OpenAIAsyncImage.swift index 12574e5..dc37f41 100644 --- a/Sources/openai-async-image-swiftui/OpenAIAsyncImage.swift +++ b/Sources/openai-async-image-swiftui/OpenAIAsyncImage.swift @@ -193,20 +193,30 @@ public extension OpenAIAsyncImage where T == OpenAIDefaultLoader{ // MARK: - File private functions - +/// A function that builds the appropriate view for a given `ImageState`. +/// - Parameter state: The current state of the image. +/// - Returns: A SwiftUI view representing the current state of the image. @ViewBuilder -fileprivate func imageTpl(_ state : ImageState) -> some View{ - switch state{ - case .loaded(let image) : image.resizable() - case .loadError(let error) : Text(error.localizedDescription) - case .loading : ProgressView() +fileprivate func imageTpl(_ state: ImageState) -> some View { + switch state { + case .loaded(let image): + image.resizable() + case .loadError(let error): + Text(error.localizedDescription) + case .loading: + ProgressView() } } +/// Maps an error to a corresponding `AsyncImageErrors` type. +/// - Parameter error: The error to map, which may be `nil`. +/// - Returns: An `AsyncImageErrors` value if the error can be mapped; otherwise, `nil`. @Sendable -fileprivate func errorMapper(_ error : Error?) -> AsyncImageErrors?{ - if error is CancellationError{ +fileprivate func errorMapper(_ error: Error?) -> AsyncImageErrors? { + if error is CancellationError { return .cancellationError } + // Return nil for other errors return nil } diff --git a/Tests/openai-async-image-swiftuiTests/openai_async_image_swiftuiTests.swift b/Tests/openai-async-image-swiftuiTests/openai_async_image_swiftuiTests.swift index 44051a3..453239c 100644 --- a/Tests/openai-async-image-swiftuiTests/openai_async_image_swiftuiTests.swift +++ b/Tests/openai-async-image-swiftuiTests/openai_async_image_swiftuiTests.swift @@ -3,9 +3,6 @@ import XCTest final class openai_async_image_swiftuiTests: XCTestCase { func testExample() throws { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct - // results. - // XCTAssertEqual(openai_async_image_swiftui().text, "Hello, World!") + } }