Image Maker is a simple SwiftUI application for iOS 17 that demonstrates basic image generation in SwiftUI and saving the generated image to the Photos app. This project aims to showcase the integration of UIKit with SwiftUI for generating random images and handling permissions to access the photo library.
- Image Generation: Generates random images with lines of random colors and widths.
- Save to Photos: Allows users to save generated images directly to their device's Photos app.
- Permissions Handling: Manages photo library access permissions seamlessly.
- iOS 17.0+
- Xcode 13.0+
- Swift 5
Clone the repository or download the project to your local machine. Open the image-maker.xcodeproj
file in Xcode. Ensure that you have the required iOS version and Xcode version to run the project.
Upon launching the app, the user is presented with a simple interface with a "Make Image" button. Tapping this button generates a random image displayed in a modal view. The user can then choose to save the image to their Photos app or close the view to generate a new image.
The ViewModel
class handles the image generation logic. It uses UIGraphicsImageRenderer
to create a UIImage with random lines drawn on it. This image is then displayed on the UI through the ImageCoverView
.
To save images to the Photos app, the app checks for permissions using PHPhotoLibrary.requestAuthorization
. If access is granted, the image is saved using PHPhotoLibrary.shared().performChanges
. Proper error handling and feedback are provided to the user.
To use the Photos library, you must include the NSPhotoLibraryUsageDescription
key in your Info.plist
file with a message describing why the app needs access to the user's photos. See comment in ViewModel.swift for detailed instructions.
The Image Maker project is released under the MIT license.