Group Group Group Group Group Group Group Group Group

Take an image and store it (Image vs UIImage)

Hello,

I am trying to take an image in SwiftUI with an Image-Picker, edit it (is missing) and save it. All components are working with the type Image, but to save the image by UIImageWriteToSavedPhotosAlbum(…) an UIImage is needed. This is my ContentView.swift:

    @State private var image: Image? = Image(systemName: "camera")

    ...

    var body: some View {
    TabView {
        VStack {
            image!
                .resizable()
                ...
                
                .aspectRatio(contentMode: .fit)
                .onTapGesture { self.shouldPresentActionScheet = true }
                .sheet(isPresented: $shouldPresentImagePicker) {
                    SUImagePickerView(sourceType: self.shouldPresentCamera ? .camera : .photoLibrary, image: self.$image, isPresented: self.$shouldPresentImagePicker)
            }.actionSheet(isPresented: $shouldPresentActionScheet) { () -> ActionSheet in
                ActionSheet(title: Text("Choose mode"), message: Text("Please choose your preferred mode"), buttons: [ActionSheet.Button.default(Text("Camera"), action: {
                    self.shouldPresentImagePicker = true
                    self.shouldPresentCamera = true
                }), ActionSheet.Button.default(Text("Photo Library"), action: {
                    self.shouldPresentImagePicker = true
                    self.shouldPresentCamera = false
                }), ActionSheet.Button.cancel()])
            }
            Button("Save to library", action: {
                // let uiimage = self.image.asUIImage <- not working 
                UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil)
                ...

I tried to convert the Image to UIImage this way but I get
“not working” means “Value of type ‘Image?’ has no member ‘asUIImage’”. Anyway this seems not the right way.

The tutorials Taking Photos and PhotoExtensions are written in Swift 3 and uses the storyboard. Is there any place for migrated tutorial source code for Swift 5?

I think this is a conceptional problem on my side, what am I doing wrong? Thank you very much